Hey,

I want to update rows in a table, using a stored procedure, with data from the next fetched row.
The StartDate of the next row has to become the EndDate of the current row.

Below is what I have been trying this far. This is just to figure how to get it to work. It doesn't include ordering the data correctly in order to get the right rows.

Any help would be very much appreciated.

Kind Regards,

Jan



CREATE PROCEDURE USP_StartDate
AS
DECLARE @StartDate datetime
DECLARE @New datetime
DECLARE cur_getstartdate SCROLL CURSOR FOR
SELECT StartDt FROM Table1
ORDER BY StartDt

OPEN cur_getstartdate
FETCH LAST FROM cur_getstartdate
INTO @StartDate

WHILE @@FETCH_STATUS = 0
BEGIN
SET @New = @StartDate

FETCH PRIOR FROM cur_getstartdate
INTO @StartDate

UPDATE BaremeExtensionReferenceSalary SET EndDt=@New

END

CLOSE cur_getstartdate
DEALLOCATE cur_getstartdate

GO