SELECT CONVERT(VARCHAR,DOB,103) AS DOB,CONVERT(VARCHAR,(SELECT RETIREDATE FROM GOVT_EMP_RETIREMENT(DOB)),103) RETIREDATE,
(SELECT RETIRESTATUS FROM GOVT_EMP_RETIREMENT(DOB)) RTDSTS
FROM TBL_EMPLOYEE
CREATE FUNCTION [dbo].[GOVT_EMP_RETIREMENT]
(
@PDOB DATETIME
)
RETURNS
@TBLRETIRESTS TABLE
(
RETIREDATE DATETIME,
RETIRESTATUS VARCHAR(16)
)
AS
BEGIN
INSERT INTO @TBLRETIRESTS
SELECT CASE WHEN ((DAY(DATEADD(yy,60,@PDOB)))> 1) THEN DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,(DATEADD(yy,60,@PDOB)))+1,0)) ELSE DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,(DATEADD(month,-1,(DATEADD(yy,60,@PDOB)))))+1,0)) END 'RETIREMENT DATE'
,CASE WHEN ((DAY(DATEADD(yy,60,@PDOB)))> 1) THEN
CASE WHEN DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,(DATEADD(yy,60,@PDOB)))+1,0)) > GETDATE() THEN 'Blue' ELSE 'RED' END
ELSE
CASE WHEN DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,(DATEADD(month,-1,(DATEADD(yy,60,@PDOB)))))+1,0)) > GETDATE() THEN 'Blue' ELSE 'RED' END END 'RTD STATUS'
RETURN
END
No comments:
Post a Comment