- DECLARE @temp TABLE (cid int, cname varchar(50))
- --Insert Data in table
- INSERT INTO @temp(cid, cname)
- values(1,'sql '),
- (5, 'ado'),
- (10,'asp'),
- (13,'php'),
- (16,'sql update'),
- (24,'sql triggers')
- DECLARE @ptopicid INT
- SET @ptopicid = 10
- -- Get Table Records
- SELECT * FROM @temp
- -- Get Previous and Next Record Ids
- SELECT (SELECT MAX(t.cid) PreviousID
- FROM @temp t
- WHERE cid < @ptopicid) PreviousId, (SELECT MIN(et.cid) NextID
- FROM @temp et
- WHERE cid > @ptopicid) NextId
This code snippet is for Get Previous and Next Row Values from Sequence in SQL Server.
