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='')

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM