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