Are there any cases of more than one sales order per customer?You also seem to be selecting to EDW for each line item?? I would get an aux table of 'ban s' without duplicates and select with for each entry in that table - iif you then manage to do fo...