Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vack
Aged Yak Warrior

USA
530 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
52326 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  
 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.01 seconds. Powered By: Snitz Forums 2000