Thursday, August 12, 2010

Some Tricky SQLs - Leave Days Count

I have following Requirement:
I have to calculate number of 'No Pay Leaves' consumed by an employee in a given period(suppose in the month of Aug 2010). Can i get the desired count in one SQL?

Solution:
In HCM System there is a Dates Attributes Table with name: 'PS_TL_DATES_TBL' (Time and Labor Module). This record will simplify our requirement as shown in the following SQL.

SELECT COUNT(A.THE_DATE)
FROM PS_TL_DATES_TBL A,PS_GP_ABS_EVENT B
WHERE B.PIN_TAKE_NUM = (SELECT PIN_NUM FROM PS_GP_PIN
WHERE PIN_NM LIKE 'TP NPL LVE')
AND B.EMPLID = '000052'
AND B.EMPL_RCD = 0
AND A.THE_DATE BETWEEN B.BGN_DT AND B.END_DT
AND A.THE_DATE BETWEEN '26-AUG-2010' AND '28-AUG-2010' ;


No comments:

Post a Comment