问题
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