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

判断语句怎摸写?
select   (case   a.delaytime   when   datediff(dd,endtime,completetime)> 0   then   abs(datediff(dd,endtime,completetime)  
end   )     DelayTime
from   projectinfo   a

实现功能:如果实际交货日期大于计划交货日期,则相减,得到延期天数
在查询分析器里用出错,不知是哪里问题?

------解决方案--------------------
select id, sum(case when datediff(dd,endtime,completetime)> 0 then abs(datediff(dd,endtime,completetime)
end ) DelayTime
from projectinfo a
group by id
------解决方案--------------------
select (case when datediff(dd,endtime,completetime)> 0 then abs(datediff(dd,endtime,completetime) else a.delaytime
end ) DelayTime
from projectinfo a
------解决方案--------------------
-try

select case when datediff(dd,endtime,completetime)> 0 then abs(datediff(dd,endtime,completetime)
end ) DelayTime
from projectinfo a


------解决方案--------------------
--ok
select case when datediff(dd,endtime,completetime)> 0 then abs(datediff(dd,endtime,completetime)) end DelayTime from projectinfo a
------解决方案--------------------
select DelayTime = case datediff(dd,endtime,completetime) when > 0 then abs(datediff(dd,endtime,completetime)
end ) DelayTime
from projectinfo a

------解决方案--------------------
select case when datediff(dd,endtime,completetime)> 0 then abs(datediff(dd,endtime,completetime)) end DelayTime from projectinfo a