Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    3

    Unanswered: 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?

  2. #2
    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;
    Last edited by r123456; 12-22-03 at 23:38.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Dec 2003
    Posts
    3
    Thanks so much - Ill give it a try!

    Cheers to you too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •