Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 for loops

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-01-19 : 12:07:40
MArk writes "I had a table of 2 columns already filled. I later decided to add a third column which will be my unique key, and auto increments after I have filled it. The table currently has over 300 rows. I want to do a for loop (or alternative) in which I have a variable initialize to 1, and auto increment by 1 and insert into the sid (my unique field) row by row so that it increases as the rows increase. Here is an algorithm for what I am trying to do.

i = 1;
while not end of rows
{
update table
set sid = i for current row
move to next row
i++
}

I would like to know how to do this in SQL, or if possible, I would like the code to do this. I am using MSSQL 7.0. I assume you would need to use transact sql to do this."
   

- Advertisement -