读书人

依条件查询数据解决方法

发布时间: 2012-09-29 10:30:01 作者: rapoo

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

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

查询[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)

读书人网 >asp.net

热点推荐