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()
和case
还有其他选择吗?
答案 0 :(得分:2)
像
这样的东西where ISNULL(@name,name) = name
and ISNULL(@lname,lname) = lname
and ISNULL(@id,id) = id