当前位置: 代码迷 >> ASP.NET >> 依条件查询数据解决方法
  详细解决方案

依条件查询数据解决方法

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

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

查询[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)
  相关解决方案