Some time we need to update value in a table in some pattern or increment order. Then we use loop and iterate with all record, but as know looping is take time and our application become slower.
We can achieve this by without loop also. below is my table and i need to update UserNo column in a order.
Here i use two variable @Increment and @initialValue. my @initialValue is the value which i want to set as staring value. In my case this is 1 and @Increment is which i have to increment like increment by 1 or increment by 2.
Declare @Increment int
Declare @initialValue int
set @initialValue = 0;
below is the my sql sqery.
set UserNo = (@Value + @Increment), @Increment= @Increment + 1