Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 coping data

Author  Topic 

Shrews14
Starting Member

37 Posts

Posted - 2007-03-21 : 11:53:19
I'm current copying data tables to other tables that don't, some which don't allow duplication of data, i'm dealing with about 40 tables. the insert errors when i try the full copy process, is there a way of saying copy the data if it's not there?

and if there is matching data ignore....... I have seen there is - if exist() would this work in this work in this case.

the only thing i can think of is to delete all the data from the table which in some case will lead to a loss of data- bad times :)

thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-21 : 11:58:53
[code]Insert into DestTbl (col1, col2, ...)
Select s.Col1, s.col2, ...
from SourceTbl s LEFT JOIN DestTbl d
on s.pk = d.pk
where d.pk IS NULL[/code]

p.k. = Primary key column

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -