select * from t where a=isnull(@a,a) and b=isnull(@b,b)b=isnull(@b,b)这是什么意思?小弟刚学这个~~
@a int=null,@b varchar(2)=null select * from t where a=isnull(@a,a) and b=isnull(@b,b) --------------------------------- 的确不明白,请解释下
select * from t where a=isnull(@a,a) and b=isnull(@b,b)當@a為null值時,那麼isnull(@a, a)的返回值為a,此時條件變成了a=a當@a不為null值時,isnull(@a, a)返回值為@a,此時條件變成了a=@a@b同理所以當@a和@b同時為null時,條件就是a=a and b=b,這時得到的結果集與select * from t是完全一樣的當@a為null,@b不為null時,條件就是a=a and b=@b,此時結果集與select * from t where b=@b完全一樣其他情況同理這樣解釋應該能懂了吧
@a int=null,@b varchar(2)=null
select * from t where a=isnull(@a,a) and b=isnull(@b,b)
create procedure QueryEmpno
@empno varchar(10) '' --默认值''
as
if (@empno = '')
select * from HumanResources.Employee
else
select * from HumanResources.Employee where EmployeeID = @empno
end--LZ要的是不是这样的情况,当我传了参数
exec QueryEmpno '25'--没参数查询所有的
exec QueryEmpno
谁还有解决办法?
select * from t where a=isnull(@a,a) and b=isnull(@b,b)
---------------------------------
的确不明白,请解释下
2樓 zsforever(虎虎) 的方法