0

Hi I have a Table that have a Primary Key [UserId] now I have just added another Column called [ReferenceNumber]. And ReferenceNumber required to update values copied from UserId in reverse. For Example: if userId =12 then ReferenceNumber would be updated by 21.

I have to loop through end of the table and update ReferenceNumber column.

 FOR LOOP TO --- From First Row to End 
     Update dbo.UserTable SET [ReferenceNumber ]=
          (SELECT REVERSE([UserId]) FROM dbo.UserTable) 
 END

Please Advice

1 Answer 1

1

Does this do what you want?

update dbo.UserTable
    set ReferenceNumber = reverse(UserId);

There is no need for an explicit "loop". The update matches all matching rows in the table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.