s

mssql how to get the previous row and next row value using select statement edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 27 November 2020 | 1551

you can use the LAG and LEAD function to get the previous and next row in SQL server while using the select statment

Solution

select LAG(Id) OVER (ORDER BY DisplayOrder) PreviousId,Id, LEAD(Id) OVER (ORDER BY DisplayOrder) NextId, DisplayOrder,ImageId from ItemImageMapping where ItemId = @ItemId