• The problem is in the design of the Refills table. It needs to have the ID of the prescription in there or in a bridge table. For something like this, I'll recommend not using a bridge table.

    The refill absolutely must be linked to the prescription which must be linked back to the customer. That's the only way this is ever going to work.

    I also would NOT call the RefillNumber that. It should be named the same as the prescription ID column so that no one has to guess or rely on esoteric knowledge to know what it is. You DID have to parenthetically explain to us what it was.

    To wit, I also wouldn't include the ID of the customer in the Refills table.

    --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)