SELECT TOP (201) d.idsaledelivery,d.idsaledeliverydetail,d.amount, d.idSaleExpenseAllocationDTO,d.SourceVoucherCode FROM dbo.SA_SaleExpenseAllocationDetail d JOIN dbo.SA_SaleDelivery h ON h.id=d.idsaledelivery WHERE h.idcustomer=:customer_id AND h.voucherdate<:until ORDER BY h.id,d.id;