且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

where子句中的条件

更新时间:2022-06-03 18:03:46

尝试:

Try:
SELECT * FROM table WHERE date=@date AND (@abc IS NULL OR abc=@abc)


你应该检查这样一个条件你的代码并执行一个不同的查询,即

You should check such a a condition in your code and execute a different query, namely
select * from table where date=@date



用于忽略'empty' abc 参数。


您可以使用if ... else ...条件来检查它是否有数据。



You can use if...else... condition to check whether it is having data or not.

if @date and @abc is not null
begin
    "Your select statement" Where date=@date and abc=@abc
end
if @date is not null and @abc is null
begin
    "Your select statement" Where date=@date 
end
if @date is null and @abc is not null
begin
    "Your select statement" Where abc=@abc
end