SELECT
  IA.BatchNumber,
  IA.ClientID,
  IA.AccountCode,
  BE.GroupName,
  IA.InvoiceNumber,
  IA.InvoiceAmountIncl,
  IA.ErrorDescription
FROM
  taInvoiceAudit AS IA
    LEFT JOIN taClients AS BE ON (BE.ClientID = IA.ClientID)
WHERE
  (IA.InvoiceType = 'Retainer') AND
  (IA.ErrorDescription = 'Success') AND
  (IA.BatchNumber = @nBatchNumber) AND
  (IA.AppointmentID = (YEAR(@aActionDate) * 100 + MONTH(@aActionDate)))

UNION

SELECT
  IA.BatchNumber,
  IA.ClientID,
  IA.AccountCode,
  BE.GroupName,
  IA.InvoiceNumber,
  IA.InvoiceAmountIncl,
  IA.ErrorDescription
FROM
  cms_archive.taInvoiceAudit AS IA
    LEFT JOIN taClients AS BE ON (BE.ClientID = IA.ClientID)
WHERE
  (IA.InvoiceType = 'Retainer') AND
  (IA.ErrorDescription = 'Success') AND
  (IA.BatchNumber = @nBatchNumber) AND
  (IA.AppointmentID = (YEAR(@aActionDate) * 100 + MONTH(@aActionDate)))
