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

Murugan Andezuthu Dharmaratnam | 27 November 2020 | 161

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


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