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

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

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄