• foxxo (3/20/2013)


    SELECT DISTINCT product_id

    FROM fact_sales

    WHERE (agent_id=1 AND product_code in (1))

    OR (agent_id=2 AND product_code in (3))

    OR (agent_id=3 AND product_code in (2))

    OR (agent_id=4 AND product_code in (1))

    AND & OR operators

    http://www.w3schools.com/sql/sql_and_or.asp

    I'm pretty sure the OP wants a return of only those things that meet all 4 pairs of conditions. By itself, OR just isn't going to do it.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)