Using SQL Server 2008
Below is the select statement I have working to determine Years of Service from an Employee table. Now, I've been asked to determine the leave time based on YOS and criteria like 1 - 4 years PTO = 80 hours; 5 - 9 = 120 hours and 10+ = 160 hours. I THINK that the first step is to write a CASE statement within the select to get the PTO for each employee based on their Years of Service, and then I need to include a column for "GRANDFATHERED" employees who already have 200 hours of PTO based on an old program.
I am a mediocre SQL coder...years of experience with Crystal Reports, but not writing queries that will return data I could write formulas for in CR. I would appreicate any help you could give. I will try to offer better examples if needed. Thanks for advance for any help you can give me.
SELECT Employee
,LastName
,FirstName
,MidName
,Race
,Sex
,CONVERT(VARCHAR(10),HireDate ,101) as HireDate
,CONVERT(VARCHAR(10),udRehireDate ,101) as RehireDate
,CONVERT(CHAR(10), ISNULL(udRehireDate,HireDate), 101) AS "Hire or Rehire Date"
,CONVERT(Decimal(5,2),(DATEDIFF(Day,ISNULL(udRehireDate,HireDate),CAST('12/31/' + CAST(YEAR(GETDATE()) AS CHAR(5)) AS DATETIME))/365.25)) as YOS
,HrlyRate
,PREC.Description
from PREH
Inner Join PREC on
PREH.PRCo = PREC.PRCo
and PREH.EarnCode = PREC.EarnCode
where PREH.PRCo = '216'
and PREH.GLCo = '216'
and PREH.JCCo = '216'
and PREH.ActiveYN = 'Y'
order by Employee
Below is the select statement I have working to determine Years of Service from an Employee table. Now, I've been asked to determine the leave time based on YOS and criteria like 1 - 4 years PTO = 80 hours; 5 - 9 = 120 hours and 10+ = 160 hours. I THINK that the first step is to write a CASE statement within the select to get the PTO for each employee based on their Years of Service, and then I need to include a column for "GRANDFATHERED" employees who already have 200 hours of PTO based on an old program.
I am a mediocre SQL coder...years of experience with Crystal Reports, but not writing queries that will return data I could write formulas for in CR. I would appreicate any help you could give. I will try to offer better examples if needed. Thanks for advance for any help you can give me.
SELECT Employee
,LastName
,FirstName
,MidName
,Race
,Sex
,CONVERT(VARCHAR(10),HireDate ,101) as HireDate
,CONVERT(VARCHAR(10),udRehireDate ,101) as RehireDate
,CONVERT(CHAR(10), ISNULL(udRehireDate,HireDate), 101) AS "Hire or Rehire Date"
,CONVERT(Decimal(5,2),(DATEDIFF(Day,ISNULL(udRehireDate,HireDate),CAST('12/31/' + CAST(YEAR(GETDATE()) AS CHAR(5)) AS DATETIME))/365.25)) as YOS
,HrlyRate
,PREC.Description
from PREH
Inner Join PREC on
PREH.PRCo = PREC.PRCo
and PREH.EarnCode = PREC.EarnCode
where PREH.PRCo = '216'
and PREH.GLCo = '216'
and PREH.JCCo = '216'
and PREH.ActiveYN = 'Y'
order by Employee