sql 工龄计算
来源:百度知道 编辑:UC知道 时间:2024/06/03 18:15:07
declare @gl int
select @gl=
(case when datepart(year,getdate())>=datepart(year,checkdate) and datepart(month,getdate())>=datepart(month,checkdate) then
datediff(year,checkdate,getdate()))
from employee
我这样写是不对的..请问该怎么改?
checkdate是到职日期
或者另外给介绍个方法..谢谢
=========================
郁闷..
select @gl=
(case when datepart(year,getdate())>=datepart(year,checkdate) and datepart(month,getdate())>=datepart(month,checkdate) then
datediff(year,checkdate,getdate()))
from employee
我这样写是不对的..请问该怎么改?
checkdate是到职日期
或者另外给介绍个方法..谢谢
=========================
郁闷..
给CASE 加个结束符号END就行了
declare @gl int
select @gl=
(case
when datepart(year,getdate())>=datepart(year,checkdate) and datepart(month,getdate())>=datepart(month,checkdate) then
datediff(year,checkdate,getdate()) end)
from employee
(case when datepart(year,getdate())>=datepart(year,checkdate) and datepart(month,getdate())>=datepart(month,checkdate) then
datediff(year,checkdate,getdate()) end case)