Hello all
I have a SQL table in my database that records salary changes of employees historically . So a particular person may have had a salary change any number of times within a given time period. What I’d like to do is write a query retrieve the last three pay changes for a particular person. I’m new to T-SQL but I was thinking along the lines of using a cursor to store the records, looping through each row and with a case statement printing the most recent pay changes by using datdiff(max(pay_start_date), pay_start_date).
There must be an easier way? Please help
The fields that I need to use are:
person_id
pay_start_date
pay_end_date
pay_amount
Thanks for your help
Pat
I have a SQL table in my database that records salary changes of employees historically . So a particular person may have had a salary change any number of times within a given time period. What I’d like to do is write a query retrieve the last three pay changes for a particular person. I’m new to T-SQL but I was thinking along the lines of using a cursor to store the records, looping through each row and with a case statement printing the most recent pay changes by using datdiff(max(pay_start_date), pay_start_date).
There must be an easier way? Please help
The fields that I need to use are:
person_id
pay_start_date
pay_end_date
pay_amount
Thanks for your help
Pat