>>>This is the complete SP >>> >>>SET QUOTED_IDENTIFIER ON >>>GO >>>SET ANSI_NULLS ON >>>GO >>>Alter PROCEDURE get_invoices >>>/*Create PROCEDURE get_invoices*/ >>> @ldStartDate DateTime, >>> @ldEndDate DateTime >>>AS >>> >>>SELECT arjobhd.custno, >>> arjobhd.customer, >>> ISNULL(ssslsman.salespn,'') as salespn, >>> arjobhd.transtype, >>> arjobtax.taxcode, >>> IsNull(arjobhd.invno,0) as invno, >>> arjob.ljob, >>> bbjthead.id, >>> ISNULL(SUM(arjob.price),0) as invoice, >>> ISNULL(SUM(arjob.frtamt),0) as freight, >>> CAST(00.00 AS decimal(10,2)) as tax, >>> CAST(00.00 AS decimal(10,2)) as cost_lab, >>> CAST(00.00 AS decimal(10,2)) as cost_mat, >>> CAST(00.00 AS decimal(10,2)) as cost_fin, >>> CAST(00.00 AS decimal(10,2)) as cost_pur, >>> CAST(00.00 AS decimal(10,2)) as Totcost, >>> CAST(00.00 AS decimal(10,2)) as TotInv, >>> CAST(00.00 AS decimal(10,2)) as profper >>> FROM arjobhd >>> LEFT JOIN arjob on arjobhd.invno=arjob.invno >>> LEFT JOIN arjobtax on arjobhd.invno=arjobtax.invno >>> LEFT JOIN bbjthead on bbjthead.ljob=arjob.ljob >>> LEFT JOIN ssslsman on arjobhd.salespnno=ssslsman.salespnno >>> WHERE >>> ( bbjthead.closedate between @ldstartdate and @ldenddate >>> AND arjobhd.invdate IS NOT NULL >>> AND bbjthead.closedate >= arjobhd.invdate ) >>> OR >>> ( arjobhd.invdate between @ldstartdate and @ldenddate >>> AND bbjthead.closedate IS NOT NULL >>> AND invdate >= bbjthead.closedate ) >>> Group by arjobhd.custno, >>> arjobhd.customer, >>> ssslsman.salespn, >>> arjobhd.transtype, >>> arjobtax.taxcode, >>> arjobhd.invno, >>> arjob.ljob, >>> bbjthead.id >>> ORDER by arjob.ljob, arjobhd.invno >>> >>> >>>GO >>>SET QUOTED_IDENTIFIER OFF >>>GO >>>SET ANSI_NULLS ON >>>GO >>> >>>>