Hi @zenbaba weldemariam
If the datatype of [Hour] column is 'Time',then try this code:
;WITH CTE AS
(
SELECT * ,DATEADD(MINUTE, 1, [Hour]) AS NewHour,LAG([Hour])OVER(ORDER BY Employee_id,[Date], [Hour],Record_Type DESC)AS LAG_Hour
FROM #TEST
)
SELECT * FROM CTE WHERE Record_Type='In Punch' AND [Hour]=LAG_Hour --Check first, then change to update
--UPDATE CTE SET [Hour]=NewHour
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.