以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  求助多参数存储过程!  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=91748)

--  作者:有点蓝
--  发布时间:2016/10/18 14:07:00
--  
和在程序判断的方法差不多

if @dt2 is null
begin
se lect * from xxx where 项目 = @item and 日期 >= @dt1
end
else
begin
if @dt1 is null
begin
se lect * from xxx where 项目 = @item and 日期 <= @dt2
end
else
begin
se lect * from xxx where 项目 = @item and 日期 >= @dt1 and 日期 <= @dt2
end
end

另外一种是动态执行sql,https://www.baidu.com/baidu?word=exec+sp_executesql&ie=utf-8&tn=myie2dg&ch=6