sql server where case when


declare @startDate datetime='2019-10-12'
declare @endDate datetime ='2019-10-13'
declare @SyncType int
declare @IsSuccess bit

SELECT [Id]
,[UpdateBy]
,(case when IsSuccess =1 then '成功'
when IsSuccess =0 then '失败'
else '' end) as [IsSuccess]
FROM [dbo].[tb_SyncLog] Where SyncTime > convert(datetime,@startDate) and SyncTime<=convert(datetime,@endDate)
and
((case when @SyncType is null then 1 else 0 end)=1 or SyncType=@SyncType)
and
(((case when @IsSuccess is null then 1 else 0 end)=1 and (IsSuccess is null or IsSuccess in (0,1))) or ((case when @IsSuccess =1 then 1 else 1 end)=1 and IsSuccess=@IsSuccess)) order by SyncTime


免责声明!

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



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