Saturday, November 26, 2022

SQL Function Lead To Get the Next Row Value

SELECT OfficeId, JoiningDate, ReleaseDate FROM trns.EmployeeTransfer WHERE EmployeeId = 521

Order By JoiningDate

------------------------------------------------------------------------------------------------------------------

SELECT OfficeId, JoiningDate, ReleaseDate  ,

isNUll(    

 LEAD(ISNULL(OfficeId,0)) OVER (ORDER BY JoiningDate)     

 , isNull(OfficeId, 0)     

 ) AS NextOfficeId     

FROM trns.EmployeeTransfer

WHERE EmployeeId = 521




No comments:

Post a Comment

Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.