SELECT
 tFinalisedTransaction201402.Duration,
 tFinalisedTransaction201402.AmountExGST,
 tFinalisedTransaction201402.Var01,
 tFinalisedTransaction201402.Var02,
 tFinalisedTransaction201402.Var03,
 tFinalisedTransaction201402.Var04,
 tFinalisedTransaction201402.Var05,
 tFinalisedTransaction201402.Var06,
 tFinalisedTransaction201402.Var07,
 tFinalisedTransaction201402.Var08,
 tFinalisedTransaction201402.Var09,
 tFinalisedTransaction201402.Var10,
 tFinalisedTransaction201402.Var11,
 tFinalisedTransaction201402.Var12,
 tFinalisedTransaction201402.Var13,
 tFinalisedTransaction201402.Var14,
 tFinalisedTransaction201402.Var15,
tFinalisedTransaction201402.CustomerCentreID,
tFinalisedTransaction201402.DepartmentID,
tFinalisedTransaction201402.GroupID,
tFinalisedTransaction201402.CustomerID
FROM
 tFinalisedTransaction201402
 LEFT JOIN (
        tInvoiceDetail INNER JOIN tInvoice
                ON tInvoiceDetail.InvoiceID = tInvoice.ID
--#                     and tInvoice.ID NOT IN (
--#                             SELECT distinct tInvoice.CreditNoteInvID
--#                             FROM tInvoice
--#                             WHERE tInvoice.CreditNoteInvID is not null
--#                     )
        )
        ON tFinalisedTransaction201402.InvoiceDetailID = tInvoiceDetail.ID
WHERE
--#  tFinalisedTransaction201402.BatchID = 43201
  tFinalisedTransaction201402.BatchID = 43215

	  AND tInvoice.InvoiceDate > dateadd(dd,15,"20140228")
	  AND tInvoice.InvoiceDate <= dateadd(mm,1,dateadd(dd,15,"20140228"))

--# exclude Victrack Rent and Calls
--#	AND tBatchType.ID <> 199
--#          
--#  and tCustomer.ShipTo = "NTT"
--#  and tInvoice.PlatinumInvoiceNo= "INV029783"
--#  and tBatch.ID = 43201
--#  and tServiceID.ServiceID = "XXXXXXXXXXX"


