PDA

View Full Version : Insert into table


ABC123

wburchell
03-21-2011, 09:49 AM
Hi, I'm building an A5 web project using a SQL Server backend. I have a table I would like to update with data from a view. The view gets updated with new jobs from SAGE accounts, I would like my table to update with these new records, the column names are the same in both view and table.

So far I have used
SELECT * INTO tableB FROM viewA
to create the destination table, giving me a copy of existing records, I would like to insert new records from here on but am having a little difficulty getting the query right!

Anyone care to flex their query muscle??? :) Many thanks.

wburchell
03-22-2011, 09:13 AM
Hi again, found my own answer. For those that need to know here is the solution:



INSERT INTO tableB
SELECT * FROM viewA
WHERE NOT EXISTS (SELECT * FROM tableB where viewA.id = tableB.id)