ALTER proc [dbo].[Rpt_JHTJobList20121114]
(
@datesta DateType=null,
@dateend DateType=null,
@rukudatesta DateType=null,
@rukudateend DateType=null,
@stat nvarchar(50)=null
)
as
begin
if
@datesta <> null or @datesta<>'' and @dateend <> null or @dateend<>'' and
@rukudatesta is null or @rukudatesta='' and @rukudateend is null or @rukudateend=''
and @stat is null or @stat=''
begin
select N'只选作业日期'
end
else if @rukudatesta <> null or @rukudatesta<>'' and @rukudateend <> null or @rukudateend<>''
and @datesta is null or @datesta='' and @dateend is null or @dateend='' and @stat is null or @stat=''
begin
select N'只选入库日期'
end
else if @stat is not null or @stat<>'' and
@rukudatesta is null or @rukudatesta='' and @rukudateend is null or @rukudateend=''
and @datesta is null or @datesta='' and @dateend is null or @dateend=''
begin
select N'只选状态'
end
else if
@stat is not null or @stat<>'' and
@datesta is not null or @datesta<>'' and @dateend is not null or @dateend<>''
and
@rukudatesta is null or @rukudatesta='' and @rukudateend is null or @rukudateend=''
begin
select N'选状态和作业日期'
end
else
begin
select N'范围外'
end
end
我带参数执行该存储过程 他都输出的是“只选作业日期” 不管那几个参数 偶尔出来“只选状态” 反正就是不安我的if else来
------最佳解决方案--------------------
@datesta <> null or @datesta<>'' and @dateend <> null or @dateend<>'' and
@rukudatesta is null or @rukudatesta='' and @rukudateend is null or @rukudateend='' and @stat is null or @stat=''
应该更改:
(@datesta <> null or @datesta<>'') and (@dateend <> null or @dateend<>'') and
(@rukudatesta is null or @rukudatesta='') and (@rukudateend is null or @rukudateend='') and (@stat is null or @stat='')