renumbering Column in a Table – SQL code

Hi, have a good day.

This SQL Script will help you to renumbering Column Rows in a Table.

DECLARE @StartCount INT
DECLARE CountCourse CURSOR FOR SELECT id FROM mytable where id = ''
SET @StartCount = 1
OPEN CountCourse
FETCH NEXT FROM CountCourse
WHILE @@FETCH_STATUS <> -1
BEGIN
 UPDATE cu000 SET id = @StartCount WHERE CURRENT OF CountCourse
 FETCH NEXT FROM CountCourse 
 SET @StartCount = @StartCount + 1
END
CLOSE CountCourse
DEALLOCATE CountCourse

Comments

Leave a Reply

Your email address will not be published.