2015-11-02 252 views
0

我有一个存储过程检索数据,过程获取2个参数作为字符串。将参数传递给存储过程som检索数据

这个程序每次都有新的参数被多次调用。

我想只调用一次该过程,并将所有参数作为参数列表发送。

这是我曾尝试

create type dbo.adressAndCity as table 
(
    [adress] string, 
    [city] string 
) 
go 

create procedure dbo.selectItems 
(
    @Items adressAndCity readonly 
) 
as 
begin 
    select * 
    from dbo.testTable 
    // the syntax below is nOt correct 
    where adress = (@Items.adress) And city = (@Items. city) 
end 

如何进入参数表中的值?

+0

这RDBMS本作是拼写错误?请添加一个标签来指定您是使用'mysql','postgresql','sql-server','oracle'还是'db2' - 或者其他的东西。 –

+0

根据所使用的语法添加了'sql-server'和'tsql'标记。 –

+0

您可以像访问表中的值一样访问表参数中的值。 –

回答

0

我相信你正在寻找一个JOIN

create procedure dbo.selectItems 
(
@Items addressAndCity readonly 
) 
as 
begin 
    select T.* from dbo.testTable T 
    INNER JOIN @Items I 
     ON T.address = i.address) 
    And T.city = I.city) 
end 

请注意,我已经纠正你的address

+0

如何访问里面的“where statment” –

相关问题