Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to update increment value in a table without loop in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 895
    Comment on it

    Hi All,

    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
    Set @Increment=0;

    Declare @initialValue int
    set @initialValue = 0;

    below is the my sql sqery.

    set UserNo = (@Value + @Increment), @Increment= @Increment + 1

     

    Thanks

     

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: