2012-04-02 29 views
0

假設有3個文本框用於名字,*姓氏*,城市。 根據文本框中的條目,將其添加到where子句中。 這是我的查詢。如何在sp中追加查詢?

select col1,col2 from table1 where 

假設把名字變成texfirstname,那麼查詢會是這樣

select col1,col2 from table1 where firstname = txtfirstname.Text 

,如果用戶在textlastname輸入姓氏然後查詢會是這樣

select col1,col2 from table1 where firstname = txtfirstname.Text and lastname = txtlastname.Text 

我正在追加基於用戶在文本框中輸入的主要查詢。

如何在存儲過程中執行此操作,如果用戶填充文本框?

回答

0
Create Procedure spTest 
(
    @Value nVarChar(10) 
) 
As 
Begin 
    Select col1,col2 from table1 where firstname = @Value 
End