日期:2014-05-18  浏览次数:20473 次

关于Case的用法
SQL code

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'
end




主要是看Case那段。

谢谢

------解决方案--------------------
修改下你原来的错误

SQL code
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())
else datediff(DAY,a.EndDate,getdate())
end = 0

------解决方案--------------------
SQL code

--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'
--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=3 and datediff(day,a.YQTime,getdate())=0 or a.Status in(0,1,2) and datediff(day,a.EndDate,getdate())=0