Blom, you amaze me. Yes, my sql was incomplete, my fault, was trying to simplify as much as possible.
If the CONTRACT_TABLE has CONTRACT = '11111'. (one row of header) with item_codes from the CONTRACT_DETAIL table of '115' and '040' (two rows of detail), then the inner script will pull two...