/* Testing - from actual program but BatchID stated. */ SELECT tDataCollection.ID AS DataRefID, tDataCollection.SequenceNo, tDataCollection.Duration, tDataCollection.CallCode, tDataCollection.ServiceID, tDataCollection.BatchID, (CASE tDataCollection.TxnDate WHEN NULL THEN NULL ELSE SUBSTRING(tDataCollection.TxnDate,7,4) + SUBSTRING(tDataCollection.TxnDate,4,2) + SUBSTRING(tDataCollection.TxnDate,1,2) + (CASE tDataCollection.TxnTime WHEN NULL THEN '' ELSE ' ' + tDataCollection.TxnTime END) END) AS TxnDate, tDataCollection.AmountExGST, tDataCollection.GSTAmount, tDataCollection.AmountIncGST, (CASE tDataCollection.FromDate WHEN NULL THEN NULL ELSE SUBSTRING(tDataCollection.FromDate,7,4) + SUBSTRING(tDataCollection.FromDate,4,2) + SUBSTRING(tDataCollection.FromDate,1,2) END) AS FromDate, (CASE tDataCollection.ToDate WHEN NULL THEN NULL ELSE SUBSTRING(tDataCollection.ToDate,7,4) + SUBSTRING(tDataCollection.ToDate,4,2) + SUBSTRING(tDataCollection.ToDate,1,2) END) AS ToDate, tDataCollection.TransactionTypeID, tDataCollection.StatusID, (CASE tDataCollection.GSTFlag WHEN 'Y' THEN 1 ELSE 0 END) AS GSTFlag, tServiceID.ActivityID, tServiceID.CentreID, tServiceID.ID AS SID, tServiceID.SubledgerID, tServiceID.CustomerCentreID, tServiceID.CustomerActivityID, tServiceID.CustomerElementID, tServiceID.CustomerSubledgerID, tServiceID.LocationID, tServiceID.UpEnd, tServiceID.UpMDF, tServiceID.DownEnd, tServiceID.DownMDF, tServiceID.Length, tServiceID.PersonID, tServiceType.ID AS ServiceTypeID, tServiceType.Code, tTransactionGroup.Description AS TransactionGroup, tServiceType.RevenueElementID, tServiceType.ExpenseElementID, tCustomer.ID AS CustomerID, tDialledNumber.ID as DialledNumberID, tOrigin.ID as OriginID, tDestination.ID as DestinationID, tRateDescription.ID AS RateDescriptionID, tDataCollection.Var01, tDataCollection.Var02, tDataCollection.Var03, tDataCollection.Var04, tDataCollection.Var05, tDataCollection.Var06, tDataCollection.Var07, tDataCollection.Var08, tDataCollection.Var09, tDataCollection.Var10, tDataCollection.Var11, tDataCollection.Var12, tDataCollection.Var13, tDataCollection.Var14, tDataCollection.Var15 FROM ((((((tDataCollection LEFT JOIN ((tServiceID LEFT JOIN (tCentre LEFT JOIN (tDepartment LEFT JOIN (tGroup LEFT JOIN tCustomer ON tGroup.CustomerID = tCustomer.ID) ON tDepartment.GroupID = tGroup.ID) ON tCentre.DepartmentID = tDepartment.ID) ON tServiceID.CustomerCentreID = tCentre.ID) LEFT JOIN tServiceType ON tServiceID.ServiceTypeID = tServiceType.ID) ON tDataCollection.ServiceID = tServiceID.ServiceID) LEFT JOIN tDialledNumber ON tDataCollection.DialledNumber = tDialledNumber.Description) LEFT JOIN tOrigin ON tDataCollection.Origin = tOrigin.Description) LEFT JOIN tDestination ON tDataCollection.Destination = tDestination.Description) LEFT JOIN tRateDescription ON tDataCollection.RateDescription = tRateDescription.Description) LEFT JOIN tTransactionType ON tDataCollection.TransactionTypeID = tTransactionType.ID) LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID WHERE tServiceID.ServiceID IS NOT NULL AND tDataCollection.BatchID = 50003 AND tServiceType.SplitService = 1 ORDER BY tDataCollection.ID /* Limited for testing - next-to-last line added */ SELECT tDataCollection.ID AS DataRefID, tDataCollection.SequenceNo, tDataCollection.Duration, tDataCollection.CallCode, tDataCollection.ServiceID, tDataCollection.BatchID, (CASE tDataCollection.TxnDate WHEN NULL THEN NULL ELSE SUBSTRING(tDataCollection.TxnDate,7,4) + SUBSTRING(tDataCollection.TxnDate,4,2) + SUBSTRING(tDataCollection.TxnDate,1,2) + (CASE tDataCollection.TxnTime WHEN NULL THEN '' ELSE ' ' + tDataCollection.TxnTime END) END) AS TxnDate, tDataCollection.AmountExGST, tDataCollection.GSTAmount, tDataCollection.AmountIncGST, (CASE tDataCollection.FromDate WHEN NULL THEN NULL ELSE SUBSTRING(tDataCollection.FromDate,7,4) + SUBSTRING(tDataCollection.FromDate,4,2) + SUBSTRING(tDataCollection.FromDate,1,2) END) AS FromDate, (CASE tDataCollection.ToDate WHEN NULL THEN NULL ELSE SUBSTRING(tDataCollection.ToDate,7,4) + SUBSTRING(tDataCollection.ToDate,4,2) + SUBSTRING(tDataCollection.ToDate,1,2) END) AS ToDate, tDataCollection.TransactionTypeID, tDataCollection.StatusID, (CASE tDataCollection.GSTFlag WHEN 'Y' THEN 1 ELSE 0 END) AS GSTFlag, tServiceID.ActivityID, tServiceID.CentreID, tServiceID.ID AS SID, tServiceID.SubledgerID, tServiceID.CustomerCentreID, tServiceID.CustomerActivityID, tServiceID.CustomerElementID, tServiceID.CustomerSubledgerID, tServiceID.LocationID, tServiceID.UpEnd, tServiceID.UpMDF, tServiceID.DownEnd, tServiceID.DownMDF, tServiceID.Length, tServiceID.PersonID, tServiceType.ID AS ServiceTypeID, tServiceType.Code, tTransactionGroup.Description AS TransactionGroup, tServiceType.RevenueElementID, tServiceType.ExpenseElementID, tCustomer.ID AS CustomerID, tDialledNumber.ID as DialledNumberID, tOrigin.ID as OriginID, tDestination.ID as DestinationID, tRateDescription.ID AS RateDescriptionID, tDataCollection.Var01, tDataCollection.Var02, tDataCollection.Var03, tDataCollection.Var04, tDataCollection.Var05, tDataCollection.Var06, tDataCollection.Var07, tDataCollection.Var08, tDataCollection.Var09, tDataCollection.Var10, tDataCollection.Var11, tDataCollection.Var12, tDataCollection.Var13, tDataCollection.Var14, tDataCollection.Var15 FROM ((((((tDataCollection LEFT JOIN ((tServiceID LEFT JOIN (tCentre LEFT JOIN (tDepartment LEFT JOIN (tGroup LEFT JOIN tCustomer ON tGroup.CustomerID = tCustomer.ID) ON tDepartment.GroupID = tGroup.ID) ON tCentre.DepartmentID = tDepartment.ID) ON tServiceID.CustomerCentreID = tCentre.ID) LEFT JOIN tServiceType ON tServiceID.ServiceTypeID = tServiceType.ID) ON tDataCollection.ServiceID = tServiceID.ServiceID) LEFT JOIN tDialledNumber ON tDataCollection.DialledNumber = tDialledNumber.Description) LEFT JOIN tOrigin ON tDataCollection.Origin = tOrigin.Description) LEFT JOIN tDestination ON tDataCollection.Destination = tDestination.Description) LEFT JOIN tRateDescription ON tDataCollection.RateDescription = tRateDescription.Description) LEFT JOIN tTransactionType ON tDataCollection.TransactionTypeID = tTransactionType.ID) LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID WHERE tServiceID.ServiceID IS NOT NULL AND tDataCollection.BatchID = 50003 AND tServiceType.SplitService = 1 AND tServiceID.ID > 20410 and tServiceID.ID < 20440 ORDER BY tDataCollection.ID