首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

依条件查询数据解决方法

2012-09-29 
依条件查询数据“状态”,“申请人”,“开始时间”,“结束时间”作为查询条件,且这些条件都可以为空。按照以往的作法

依条件查询数据
“状态”,“申请人”,“开始时间”,“结束时间”作为查询条件,且这些条件都可以为空。
按照以往的作法,要判断好多种情况,要写一大堆判断语句。现在想请问有没有其他的更好的方法。谢谢!

状态【 】
申请人【 】
开始时间【 】结束时间【 】

查询[color=#0000FF][/color]


[解决办法]
任何方法都要针对每一个条件写判断语句。
[解决办法]
首先sql使用参数 类似
select * from tabe1 where 
( (condition =@condition and @condition is not null ) or @condition is null)
and ((request =@request and @request is not null ) or @request is null)
and ((datetime >=@starttime and @starttime is not null ) or @starttime is null)
and ((datetime <=@endtime and @endtime is not null ) or @endtime is null)

热点排行