SELECT TOP (201) b.id,b.idSaleDeliveryDTO,b.idinventory,i.code AS product_code, i.name AS product_name,i.specification,cl.name AS source_class, b.quantity,b.taxPrice,b.taxAmount,b.expenseAmount,b.costPrice,b.costAmount FROM dbo.SA_SaleDelivery_b b JOIN dbo.SA_SaleDelivery h ON h.id=b.idSaleDeliveryDTO LEFT JOIN dbo.AA_Inventory i ON i.id=b.idinventory LEFT JOIN dbo.AA_InventoryClass cl ON cl.id=i.idinventoryclass WHERE h.idcustomer=:customer_id AND h.voucherdate<:until ORDER BY h.voucherdate,h.id,b.id;