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.
Author |
Topic |
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2012-02-17 : 10:26:55
|
hi , i need to insert several records from one table to another onebut the poblem is,i need to insert almost 1000 record in the table "makes"from the table "2012" lets create the tablesCREATE TABLE [dbo].[makes]( [idmake] [int] IDENTITY(1,1) NOT NULL, [make] [varchar](50) NOT NULL, [index] [int] NOT NULL) ON [PRIMARY]CREATE TABLE [dbo].[2012]( [idmake] [int] IDENTITY(1,1) NOT NULL, [make] [varchar](50) NOT NULL) ON [PRIMARY]lets put some record on table "2012" to simulate my real tableINSERT INTO [vehicle].[dbo].[2012] ([make]) VALUES ('AUDI'), ('BMW'),('PORSCHE'),('MASERATI')GONOW i need to insert all the records from table "2012" to table "makes"something like thisINSERT INTO [vehicle].[dbo].[makes] ([make] ,[index])select make, X--(variable need to be increased one for each row inserted beginning in 500)from 2012GObut i dont know how to do for inccrease the x variablethe result that i need is on the table "makes"idmake make index1 audi 500 ( starts in 500)2 bmw 501 (add 1)3 porsche 502 (add 1)etcany help, any examplemany thanks in advancedGO |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-02-17 : 10:43:42
|
One option would be to use the ROW_NUMBER() function. |
 |
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|