2012年3月24日星期六

Dr Dre Headphones以后我们做多条件查询

以后我们做多条件查询,一种是排列结合,另一种是动态拼接SQL
如:我们要有两个条件,一个日期@addDate,Dr Dre Beat,一个是@name
第一种写法是
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

第二种就是动态组成SQL,通过exec来执行,我就不写,
昨天我想到一种办法
select * from table where (addDate = @addDate or @addDate is null) and (name = @name or @name = '')
结果一调试,Coach Bag,成功,
一点想法,Moncler Women Jackets,有更好方法的,Beats By Dre,请指教,Dr Dre Headphones!~

Related articles:

没有评论:

发表评论