第一种写法是 感觉代码有些冗余
if (@adddate is not null) and (@name <> '')
select * from table where adddate = @adddate and name = @name
else if (@adddate is not null) and (@name ='')
select * from table where adddate = @adddate
else if(@adddate is null) and (@name <> '')
select * from table where and name = @name
else if(@adddate is null) and (@name = '')
select * from table
第二种写法是
select * from table where (adddate = @adddate or @adddate is null) and (name = @name or @name = '')
第三种写法是
select * from table where adddate = case @adddate is null then adddate else @adddate end,name = case @name when '' then name else @name end