SQL Replace an ID # of a bottom row to a certain ID # - I and increment all the rest of the rows ID # with 1 starting with the row that carries this
How do I replace in SQL an ID # of a bottom row to a certain ID # - I, and increment all the rest of the rows ID # with 1 starting with the row that carries this ID # -I?
--This is what I tried, and simply got confused. DECLARE @i int = 386 update tbl_ID set ID = @i+1 where ID = @i OFFSET (@Skip) ROWS FETCH NEXT (@Take) ROWS ONLY if ID = @i+1 @i = @i+1 WHILE @i < 388 BEGIN SET @i = @i + 1 update tbl_ID set ID = @i where ID = @i - 1 if ID = @i OFFSET (@Skip) ROWS FETCH NEXT (@Take) ROWS ONLY
END
Comments
Post a Comment