Click here to Skip to main content
15,907,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

SQL
INSERT INTO tablename(select colnames from tablename)
, when I run this query I get an error.
Posted
Updated 30-Oct-11 23:37pm
v3
Comments
AditSheth 31-Oct-11 4:32am    
check that both table have same column..
And can you post error message you get?
Mehdi Gholam 31-Oct-11 4:34am    
You must remove primary key column from your select as you cannot insert primary keys like this.
K N R 31-Oct-11 4:34am    
Incorrect syntax near the keyword 'select'.

What is the error you are getting?

Syntax for INSERT INTO statement is as follows:
SQL
INSERT INTO destination_table (column1, column2, column3) from (select column1, column2, column3 from source table);

Respective column types should match.
 
Share this answer
 
v2
Use this syntax
SQL
INSERT INTO Table1 (FirstName, LastName)
SELECT FirstName, LastName
FROM Table2
 
Share this answer
 
read these resources :

http://www.w3schools.com/sql/sql_select_into.asp[^]

http://msdn.microsoft.com/en-us/library/ms190750.aspx[^]

and consider that your source and destination table are the same :-?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900