sql:where中多种状况简便写法

字段名:Bran,block,are ,store 四个字段中存在值等于0或者不等于0,两种情况。where中如果用if等条件判断会有16中组合,如果采用where中的条件就避免了这个情况。

declare @a int

declare @b int

declare @c int

declare @d int

set @a=0

set @b=0

set @c=0

set @d=0

select * from ABC_Table

where (b.Bran =@a  or @a=0)

and  (b.block =@b or @b=0)

and  (b.are =@c or @c=0)

and  (a.store =@d or @d=0)

posted @ 2013-07-19 10:29  笑看天下  阅读(686)  评论(0编辑  收藏  举报