sql 存储过程参数为空则不作为条件

select DocDetailedNo,CombinedCode,a.ProjectName,DocOperCode,a.PatientID,a.CreateTime,a.ExecutiveDepName ,a.ExecutiveDepNo ,
from ApplyInfo a
left join ApplyAfterDealInfo ap on a.DocDetailedNo=ap.AppFormNo
where 1=1
and a.DocOperCode<>'CA'
and a.ExecutiveDepNo = @DepNo
and ap.StudyStatus<>'3'
and ap.StudyStatus<>'2'
and Convert(char(10),a.CreateTime,120) between @time and @timeEnd
and (a.PatientID in(@Backup2) OR @Backup2='')

以上这种写法可不需要拼接字符串方式 动态处理参数值为空时不作为 筛选条件

原文地址:https://www.cnblogs.com/0819lsl/p/10839916.html