示例:(检查活动和非活动)
持续时间 - 自日期:2011-01-01 至日期:2014-01-01
EMPID ACTIVEDATE/REJOINING DATE INACTIVEDATE
----- ------------------------ -----------
1 NULL '2011-12-31'
2 '2012-01-01' '2011-12-31'
2 NULL '2013-12-31'
3 '2015-01-01' '2011-12-31'
我需要以下输出:
Active
EMPID
-----
EMPID
-----
1
2
3
请发送确切的SQL查询并满足我的条件。
此致 维诺
答案 0 :(得分:0)
试试这个......
SELECT EmployeeID,CASE WHEN (ISNULL(MAX([REJOINING DATE]),'') > GETDATE()) OR (MAX(INACTIVEDATE) >ISNULL(MAX([REJOINING DATE]),'') ) THEN 'INACTIVE'
WHEN (MAX(INACTIVEDATE) < ISNULL(MAX([REJOINING DATE]),'') ) AND (ISNULL(MAX([REJOINING DATE]),'') < GETDATE()) THEN 'ACTIVE'
ELSE 'N/A'
END AS 'Status'
FROM @Table