If Variable is Blank Then No Where Clause

喜欢而已 提交于 2019-12-11 06:32:34

问题


I am trying to do what the below pseuedo code infers:

WHERE 
CASE 
WHEN @test <> '' THEN Agent = @test
ELSE --no where clause 
END

What is the correct structure for this?


回答1:


use OR:

select * from yourTable
where @test = '' OR Agent = @test

if @test coming with null value (instead of ''), you must use:

select * from yourTable
where @test is null OR Agent = @test


来源:https://stackoverflow.com/questions/11528875/if-variable-is-blank-then-no-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!