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
 General SQL Server Forums
 New to SQL Server Programming
 Update field w/ count starting with specific #

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-12-12 : 15:07:54
I want to update a field in a table with an ID number and I want it to start with 500. So each sequential row will be one higher.

update cicmpy
set ID = (?????)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-12 : 15:09:46
You can utilize the ROW_NUMBER() function for this. Why don't you just use an identity column instead though?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-12-12 : 15:15:53
This is SQL 2000.

When I try that I get row_number is not a recognized function name.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-12 : 15:22:25
If you are using SQL 2000, then you should always specify that in the post or put your question in the 2000 forum. 2000 is ancient these days.

You'll need a tally table to do this then since ROW_NUMBER() function wasn't added until 2005.

So why can't you just use an identity column?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-12-12 : 15:39:20
I'm dealing with two databases that use the same program. Each were populated with customers. Now I'm trying to merge the two. Do there is an ID column. In both tables they both started at 1 and incremented each time a new customer was added. I need to take one of the tables and start with the highest number from the other and increment it.

I'm not sure how I can use an Identity column for this? Can you explain further.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-12 : 15:55:35
I would just bump one up by a number that puts it higher than the first set:

update cicmpy
set ID = ID + 100

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -