使用一个存储过程实现多条件查询

来源:互联网 发布:淘宝网三星a9手机壳 编辑:程序博客网 时间:2024/05/21 18:35
在开发过程中,经常要写存储过程实现搜索,但搜索条件在不同的模块可能是不同的;因此能否用一个存储过程来实现不同的条件查询呢? 答案是肯定的。



CREATE   proc GetReportInfoOfSendBook

  @condition nvarchar(500)


  as


   exec( 'select b.sendbookname ,a.ordernumber ,a.BookName ,a.PayPrintBillID ,a.printpapernumber,a.price ,b.sendbooknum,b.discount,Edition,ProfileEdition ,
a.price*b.sendbooknum*(case b.discount when 0 then 1.00 else b.discount /100 end) as maYang

 from
Tb_payprintbill a,tb_sendbookinfo b where a.payprintbillid=b.payprintbillid and billstatusID<>2
'+@condition+'  order by b.sendbookname')
GO



原创粉丝点击