3
create Procedure Proc_selectEmp
(
@name varchar(10) = null,
@lname varchar(10) = null,
@id varchar(10) = null

)
as
begin

select * from Emp
where 
(@name is null or name = @name) 
and (@lname is null or lname = @lname) 
and (@id is null or id = @id)
end

我的基本查询:select * from Emp. 如果用户输入名称,它将被添加并且查询将是:

select *  
from Emp 
where name = txtname.Text

这是我的sp。它处理得当。

isnull()使用and是否还有其他选择case

4

1 回答 1

2

像这样的东西怎么样

where   ISNULL(@name,name) = name  
and     ISNULL(@lname,lname) = lname
and     ISNULL(@id,id) = id
于 2012-09-06T11:45:34.057 回答