取工作年限

DECLARE @WorkDate DATETIME
SET @WorkDate='2010-2-20'

select DATEDIFF(YY,@WorkDate,GETDATE()),
DATEDIFF(MM,@WorkDate,GETDATE()),
DATEDIFF(d,@WorkDate,GETDATE()),
case when DATEADD(year,DATEDIFF(YY,@WorkDate,GETDATE()),@WorkDate)>GETDATE()-1 THEN DATEDIFF(YY,@WorkDate,GETDATE())-1
ELSE DATEDIFF(YY,@WorkDate,GETDATE()) END AS WorkYear

posted @ 2011-02-21 14:41  星火卓越  阅读(197)  评论(0编辑  收藏  举报