If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Please help the new girl w/ sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-03, 17:30
zubby01 zubby01 is offline
Registered User
 
Join Date: Dec 2003
Posts: 3
Please help the new girl w/ sql

I have 2 tables. Table_A and Table_B


At the end of a function, I want to ensure that there is a
Table_B record for each Table_A record. IE Find items for the
col_a,col_b,col_c on Table_A that are not in Table_B.

* = key col's
Table_A................Table_B
*col_a..................*col_a
*col_b..................*col_b
*col_c..................*col_c
*col_d...................col_d
*col_e
col_f

If a corresponding Table_B row doesn't exist, it should be created.
The Table_B records created will have col_d = to the sum of
Table_A.col_e. How can I do this?
Reply With Quote
  #2 (permalink)  
Old 12-22-03, 20:59
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
insert into table_B
select A.col_a, A.col_b, A.col_c,
sum(A.col_a+A.col_b+A.col_c+A.col_d+A.col_e)
from table_A A
LEFT OUTER JOIN
table_B B ON
A.col_a = B.col_a AND
A.col_b = B.col_b AND
A.col_c = B.col_c
where B.col_a is null
group by A.col_a, A.col_b, A.col_c;
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

Last edited by r123456; 12-22-03 at 22:38.
Reply With Quote
  #3 (permalink)  
Old 12-22-03, 21:04
zubby01 zubby01 is offline
Registered User
 
Join Date: Dec 2003
Posts: 3
Thanks so much - Ill give it a try!

Cheers to you too.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On