// Existing SQL statement **************************** //**************************************************** UPDATE tServiceID SET tServiceID.CurrentRent = TT.RentAmt, tServiceID.CurrentCalls = TT.CallAmt FROM ( SELECT tTransaction.ServiceID, tTransaction.ServiceTypeID, Sum(CASE tTransactionGroup.Description WHEN 'RENT' THEN tTransaction.AmountExGST ELSE 0 END) AS RentAmt, Sum(CASE tTransactionGroup.Description WHEN 'CALL' THEN tTransaction.AmountExGST ELSE 0 END) AS CallAmt FROM ((tTransaction LEFT JOIN tServiceID ON tTransaction.ServiceID = tServiceID.ID) LEFT JOIN tTransactionType ON tTransaction.TransactionTypeID = tTransactionType.ID) LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID WHERE tTransaction.BatchID = 11111 AND tTransaction.RevenueFlag <> 1 AND tServiceID.ServiceTypeID = tTransaction.ServiceTypeID GROUP BY tTransaction.ServiceID, tTransaction.ServiceTypeID ) AS TT WHERE tServiceID.ID = TT.ServiceID AND tServiceID.ServiceTypeID = TT.ServiceTypeID ******************************************************* // Is this better/same for rent only? ***************** UPDATE tServiceID SET tServiceID.CurrentRent = TT.RentAmt FROM ( SELECT tTransaction.ServiceID, tTransaction.ServiceTypeID, Sum(tTransaction.AmountExGST) AS RentAmt FROM ((tTransaction LEFT JOIN tServiceID ON tTransaction.ServiceID = tServiceID.ID) LEFT JOIN tTransactionType ON tTransaction.TransactionTypeID = tTransactionType.ID) LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID WHERE tTransaction.BatchID = 11111 AND tTransaction.RevenueFlag <> 1 AND tTransactionGroup.Description LIKE 'RENT' AND tServiceID.ServiceTypeID = tTransaction.ServiceTypeID GROUP BY tTransaction.ServiceID, tTransaction.ServiceTypeID ) AS TT WHERE tServiceID.ID = TT.ServiceID AND tServiceID.ServiceTypeID = TT.ServiceTypeID ******************************************************* // Is this better for call only? ******************** UPDATE tServiceID SET tServiceID.CurrentCalls = TT.CallAmt FROM ( SELECT tTransaction.ServiceID, tTransaction.ServiceTypeID, Sum(tTransaction.AmountExGST) AS CallAmt FROM ((tTransaction LEFT JOIN tServiceID ON tTransaction.ServiceID = tServiceID.ID) LEFT JOIN tTransactionType ON tTransaction.TransactionTypeID = tTransactionType.ID) LEFT JOIN tTransactionGroup ON tTransactionType.TransactionGroupID = tTransactionGroup.ID WHERE tTransaction.BatchID = 11111 AND tTransaction.RevenueFlag <> 1 AND tTransactionGroup.Description LIKE 'CALL' AND tServiceID.ServiceTypeID = tTransaction.ServiceTypeID GROUP BY tTransaction.ServiceID, tTransaction.ServiceTypeID ) AS TT WHERE tServiceID.ID = TT.ServiceID AND tServiceID.ServiceTypeID = TT.ServiceTypeID