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
 Insert

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-04 : 05:25:06
insert into tableA (column1, column2, column3)
select distinct c1, c2, c3 from tableB

I'm scheduling a daily basis to insert into tableA.
How can I avoid inserting the same data?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-04-04 : 05:31:18
[code]
WHERE NOT EXISTS
(
SELECT *
FROM tableA x
WHERE x.c1 = tableB.c1
AND x.c2 = tableB.c2
. . .
)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-04 : 05:35:56
Where shall I apply the Insert command?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-04-04 : 06:07:03
[code]
insert into tableA (column1, column2, column3)
select distinct c1, c2, c3
from tableB
WHERE NOT EXISTS
(
SELECT *
FROM tableA x
WHERE x.c1 = tableB.c1
AND x.c2 = tableB.c2
. . .
)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -