I have a StartDate and EndDate for a Pay Code. This tracks when employees rates changed by pulling the first and last time they got paid at any given rate. I need the StartDate for the next increase to be the EndDate from from the previous record plus one day.
My code
select RateStartDate, RateEndDate - 1 as RateEndDate, PEmployeeID,PincomeCode, PRate from (SELECT min (rs_CPYPayCodeDates.MinPayCodeDate) as RateStartDate, max(rs_CPYPayCodeDates.MaxPayCodeDate) AS RateEndDate, rs_CPYPayCodeDates.PEmployeeID , rs_CPYPayCodeDates.PIncomeCode, rs_CPYPayCodeDates.Prate FROM rs_CPYPayCodeDates GROUP BY rs_CPYPayCodeDates.PEmployeeID, rs_CPYPayCodeDates.PIncomeCode, rs_CPYPayCodeDates.Prate)A where PEmployeeID = '645' and PIncomeCode = 'ST'
Code for rs_CPYPayCodeDates
SELECT min(CPY50260.PDate) AS MinPayCodeDate, max(CPY50260.PDate) AS MaxPayCodeDate, CPY50260.PEmployeeID, CPY50260.PIncomeCode, CPY50260.Prate FROM CPY50260 WHERE CPY50260.PIncomeCode IN (SELECT PIncomeCode FROM CPY10060 WHERE PPayrollCodeType = 1) AND CPY50260.PIncomeCode IN (SELECT DISTINCT UprTrxCD FROM Logbook WHERE AA_Job_# <> 'NONE') AND CPY50260.PYear = (SELECT datepart(yy,(SELECT getdate())) - 1) GROUP BY CPY50260.PEmployeeID, CPY50260.PIncomeCode, CPY50260.Prate UNION SELECT min(CPY30260.PDate) AS MinPayCodeDate, max(CPY30260.PDate) AS MaxPayCodeDate, CPY30260.PEmployeeID, CPY30260.PIncomeCode, CPY30260.Prate FROM CPY30260 WHERE CPY30260.PIncomeCode IN (SELECT PIncomeCode FROM CPY10060 WHERE PPayrollCodeType = 1) AND CPY30260.PIncomeCode IN (SELECT DISTINCT UprTrxCD FROM Logbook WHERE AA_Job_# <> 'NONE') GROUP BY CPY30260.PEmployeeID, CPY30260.PIncomeCode, CPY30260.Prate
My results
The results I need
This is just for one employee but I need the code to work for all employees. My code works fine, as far as it goes, for all employees. The only other requirement is that the code would need to work as an SQL view.
Thanks