Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO after compare tables

Status
Not open for further replies.

karlomutschler

Programmer
Jun 5, 2001
75
DE
hi all,
after comparing two identical tables (source, destination)
with

select s.col1, s.col2, s.col3
from source s
where whereclause
and and 1 = some condition
and and 2 = another condition
and (s.col1, s.col2) not in
(select col1, col2
from destination)

the difference in data is displayed.

How would I INSERT (this difference) INTO the destination table ?

Any help much appreciated.
Kind regards
Karlo

meistertools@gmx.net
 
sorry the query was not complete:

select s.col1, s.col2, s.col3, count(*)
from source s
where whereclause
and and 1 = some condition
and and 2 = another condition
and (s.col1, s.col2) not in
(select col1, col2
from destination)
group by s.col1, s.col2

meistertools@gmx.net
 
Karlo,

First, I don't believe you want the count(*) in the destination table, true?

Second, if you have even one expression in your SELECT that is a GROUP expression, then all of your expressions must be GROUP expressions. Therefore, you must include column "s.col3" in the GROUP BY list.

To do what you request, then, your code would look like this:

Insert into destination
select s.col1, s.col2, s.col3
from source s
where whereclause
and and 1 = some condition
and and 2 = another condition
and (s.col1, s.col2) not in
(select col1, col2
from destination)
group by s.col1, s.col2, s.col3;

Let us know if this is what you wanted.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top