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)
 Adding sequencial numbers (unique) to a new column

Author  Topic 

cronincoder
Yak Posting Veteran

56 Posts

Posted - 2007-01-29 : 15:20:35
I've added a id_col column to a table so that I can add sequential unique numbers

alter table
mytable
add
id_col varchar2(20) NOT NULL;

I now want to populate this table with unique numbers starting at:
1
2
3
4
5
.....

but I'm sure of the update query for this..any ideas?



SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-29 : 15:24:19
VARCHAR2 is not a valid SQL Server data type.
Which are the other columns in the table?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

cronincoder
Yak Posting Veteran

56 Posts

Posted - 2007-01-29 : 15:28:17
sorry, just varchar
Go to Top of Page

cronincoder
Yak Posting Veteran

56 Posts

Posted - 2007-01-29 : 15:29:59
other columns are:
account_number
name
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-29 : 15:36:11
update t1
set t1.id_col = (select cast(count(*) as varchar) from table1 as t2 on t2.account_number <= t1.account_number)
from table1 as t1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -