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
 Insert increment column

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2012-12-20 : 14:22:53
I want to insert records into a table. On one of the columns I need to increment the column by one.


insert into partner(
cus_no,
cus_name,
TP_id
)
select
cus_no,
cusname,
123001+1????,
from acecustomer


Data would look like:
ABC customer1 1230001
DEF Customer2 1230002
GHI Customer3 1230003

I need the TPID to start at a specific value.




visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-20 : 14:31:45
[code]
DECLARE @StartValue int

SET @StartValue = 123001

insert into partner(
cus_no,
cus_name,
TP_id
)
select
cus_no,
cusname,
@StartValue + ROW_NUMBER() OVER (ORDER BY (SELECT 1))
from acecustomer
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -