Moving data from one table to another, with check

Last Post 07 Nov 2008 05:11 AM by jend1. 2 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
jend1
New Member
New Member

--
07 Nov 2008 02:40 AM
Hi,

I'm fairly new to SQL and wondered if anyone could give me some pointers?

I have 2 exact tables but on different sql databases (on the same server). I want to load the data from one table to the other but checking that it does not already exist first and not loading that row if it does.

Any suggestions would be appreciated.

thanks.
SwePeso
New Member
New Member

--
07 Nov 2008 03:04 AM
INSERT TargetTable
(
col1,
col2
)
SELECT st.col1,
st.col2
FROM SourceTable AS st
LEFT JOIN TargetTable AS tt ON tt.col1 = st.col1
AND tt.col2 = st.col2
WHERE tt.col1 IS NULL
jend1
New Member
New Member

--
07 Nov 2008 05:11 AM
Thanks for the speedy responses, sorted now.

Thanks very much


Acceptable Use Policy
---