2015-11-02 134 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」 –

相關問題