首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

关于Case的用法,该怎么解决

2012-05-05 
关于Case的用法SQL codeselect distinct b.[Name],b.Phone from TaskInfo a left join UserInfo b on (a.M

关于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.Statuswhen '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.Statuswhen '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'--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 

热点排行