Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
I need to move data from Intel_Data table into Intel_MainDataTable table into sql Server. I have following query

SQL
INSERT INTO Intel_MainDataTable 
    SELECT * 
    FROM Intel_Data
    WHERE Intel_MainDataTable.id != Intel_Data.id

C#
But this code gives errors, it says that Intel_MainDataTable.id donn't exists. Both Tables have same fields. They are identical. Who can help me to write correct this query ?
Posted
Updated 2-Jan-16 1:09am
v2

Try select into.
SELECT *
 INTO Intel_MainDataTable
 FROM Intel_Data Intel_MainDataTable;


Some more info - SQL SELECT INTO Statement[^].
 
Share this answer
 
Comments
dave_bulac 2-Jan-16 7:16am    
No it isn't working. It says: The multi-part identifier "Interl_MainDataTable.id" couldn't be found
Try:
INSERT INTO newtable
SELECT * FROM oldtable
WHERE oldtable.id not in
(select id from newtable)

Or
INSERT INTO newtable
SELECT * FROM oldtable
WHERE NOT EXISTS
(SELECT * from newtable where id=oldtable.id);
 
Share this answer
 
v2
Comments
dave_bulac 2-Jan-16 10:09am    
Thank you very much

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