sql server - Update SQL with consecutive numbering -


I want to update a table with constant numbering starting at 1. There is a section in the update, so only the result will be re-named the clause. Can I complete it efficiently without using a temporary table?

This probably depends on your database, but this is a solution for MySQL 5 which includes a variable Use of:

  SET @a: = 0; UPDATE table SET field = @ a: = @ a + 1 WHERE whatever = 'whatever' ORDER BY field2, field3  

You should probably edit your question and this indicates What database are you using?

Editing: I used T-SQL for SQL Server This is similar to the MySQL method:

  DECLARE @ myVar int SET @ myVar = 0 update myTable SET @ myvar = myField = @myVar + 1  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -