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)
 query to put the serialnumbers for all the records

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2005-06-15 : 16:57:34
Please, Is it possible to write an update statement to put the serial number starting with 1 incrementing by 1 for each record.

I have a table labels,

i want to put serial numbers under field labelid.

Thank you very much for the information.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-06-15 : 18:10:47
Take a look at the following code example. The part that you are interested is the update statement. Try this out on your machine as is to see the before image of the table and the after image.



DECLARE @i int
SET @i = 0

CREATE TABLE Table1(Column1 char(1), Column2 int)

INSERT INTO Table1 (Column1) VALUES('A')
INSERT INTO Table1 (Column1) VALUES('B')
INSERT INTO Table1 (Column1) VALUES('C')
INSERT INTO Table1 (Column1) VALUES('D')
INSERT INTO Table1 (Column1) VALUES('E')

SELECT *
FROM Table1

UPDATE Table1 SET Column2 = @i, @i = @i + 1

SELECT *
FROM Table1

DROP TABLE Table1



Tara
Go to Top of Page
   

- Advertisement -