1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

difficult pivot?

Discussion in 'SQL - Questions and Answers' started by Berny, Jul 11, 2006.

  1. Berny Guest

    Dialect: Access
    hi!

    for a pivot view in our project database i need to join two tables.

    table bills
    ----
    customer_id project_id month year price

    table payments
    ----
    customer_id month year payment

    desired result
    ----
    customer_id project_id month year price payment

    desired example:
    customer 2 is participating in project 2 & 3. - payment should be equal in line 2 and 3.
    ----
    row 1: 1 2 1 2006 0 300
    row 2: 1 2 2 2006 1,000 500
    row 3: 1 3 2 2006 150, 500
    row 4: 1 2 3 2006 750 0

    if i use the code below i always miss line 1 because there is no entry for the second table. of course not, [...]

    SQL:

    select customer_id, project_id, month, year, price, (select price from bills where bills.customer_id=payments.customer_id and bills.month=payments.month and bills.year=bills.year) from payments


    i didn't figure out how to solve that in access. - i know it would be easier in a stored procedure, though, do you have an idea to solve my gordian knot?

    cheers

Share This Page