Reputation: 7164
I want to copy some columns from one table to another table at the same time. This is my query :
INSERT INTO [db_new].[dbo].[Element](Number, ElementNumber)
SELECT (NUMBER, ELEMENTNUMBER)
FROM [db_old].[dbo].[ELEMENTS]
I get this error for this query :
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ','.
How can I safely copy multiple columns at the same time? Thanks.
Upvotes: 1
Views: 2879
Reputation: 25753
For this operation you need use select as a standard query as below
INSERT INTO [db_new].[dbo].[Element](Number,ElementNumber)
SELECT NUMBER, ELEMENTNUMBER FROM [db_old].[dbo].[ELEMENTS]
Upvotes: 4
Reputation: 20489
The correct syntax is:
INSERT INTO [db_new].[dbo].[Element] (Number, ElementNumber)
SELECT NUMBER
,ELEMENTNUMBER
FROM [db_old].[dbo].[ELEMENTS]
Upvotes: 6