关于Case的用法
select distinct b.[Name],b.Phone from TaskInfo a left join UserInfo b on (a.Members=b.[Name] or a.Principal=b.[Name])where a.Status in ('0','1','2','3') and case a.Statuswhen '3' then 'datediff(day,a.YQTime,getdate())=0'else 'datediff(a.EndDate,getdate())=0'end
select distinct b.[Name],b.Phone from TaskInfo a left join UserInfo b on (a.Members=b.[Name] or a.Principal=b.[Name])where a.Status in ('0','1','2','3') and case a.Statuswhen '3' then datediff(day,a.YQTime,getdate())else datediff(DAY,a.EndDate,getdate())end = 0
[解决办法]
--select distinct b.[Name],b.Phone from TaskInfo a left join UserInfo b on (a.Members=b.[Name] or a.Principal=b.[Name])--where a.Status in ('0','1','2','3') and --case a.Status--when '3' then 'datediff(day,a.YQTime,getdate())=0'--else 'datediff(a.EndDate,getdate())=0'--endselect distinct b.[Name],b.Phone from TaskInfo a left join UserInfo b on (a.Members=b.[Name] or a.Principal=b.[Name])where a.Status=3 and datediff(day,a.YQTime,getdate())=0 or a.Status in(0,1,2) and datediff(day,a.EndDate,getdate())=0