随笔-13  评论-29  文章-31  trackbacks-0
以后我们做多条件查询,一种是排列结合,另一种是动态拼接SQL
如:我们要有两个条件,一个日期@addDate,一个是@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 = '')
结果一调试,成功.


转自: http://www.cnblogs.com/edobnet/archive/2005/08/07/24781.html#209403
posted on 2005-08-08 16:57 生活像一团麻 阅读(726) 评论(0)  编辑 收藏 引用 所属分类: 数据库知识
只有注册用户登录后才能发表评论。
来的都是客, 欢迎给我留言!
<2025年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(6)

随笔档案

文章分类

文章档案

收藏夹

有用的链接

最新随笔

搜索

  •  

最新评论

阅读排行榜

评论排行榜