Friday, 12 October 2012

How to find missing sequence number in a column of sql table?

Answer:-

UPDATE a
SET a.seq = b.seq+1FROM table1 AS a(NOLOCK)INNER
JOIN table1
AS b(NOLOCK)LEFT
OUTER JOIN table1 AS c(NOLOCK)ON b.seq + 1 = c.seqON a.seq-1 = a.seq+1WHERE b.seq IS NULL