SQL条件控制(case when...then...else...end)

1:
select ByeTime,case when len(ByeTime)>0 then str(DATEDIFF(day,ComeInTime,ByeTime)) else DATEDIFF(day,ComeInTime,getdate()) end as test
from myUser where DelFlag='0' and UserID='cq'
2:
select ByeTime,case when len(ByeTime)>0 then str(DATEDIFF(day,ComeInTime,ByeTime))+'(已离职)' end as test
from myUser where DelFlag='0' and UserID='cq'
3:
select ByeTime,case when len(ByeTime)>0 then str(DATEDIFF(day,ComeInTime,ByeTime))+'(已离职)'
else str(DATEDIFF(day,ComeInTime,getdate())) end as test
from myUser where DelFlag='0' and UserID='cq'

posted @ 2008-12-20 17:33  _晨阳_  阅读(1418)  评论(0编辑  收藏  举报