SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert increment column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vack
Constraint Violating Yak Guru

USA
497 Posts

Posted - 12/20/2012 :  14:22:53  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 12/20/2012 :  14:31:45  Show Profile  Reply with Quote

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


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000