SELECT B.[CID] AS "360ClientId", B.[CName] AS "360ClientName", B.[CAddress] AS "360ClientAddress", B.[CCity] AS "360ClientCity", B.[CState] AS "360ClientState", B.[CZip] AS "360ClientPostalCode", B.[CountryCode] AS "360CountryCode", CASE WHEN B.[CRef3Phone] IS NULL THEN 1 ELSE 0 END AS "360Active",
  C.[Id] AS "MDMClientId", C.[Name] AS "MDMClientName", C.[Address] AS "MDMClientAddress", C.[City] AS "MDMClientCity", C.[State] AS "MDMClientState", C.[PostalCode] AS "MDMClientPostalCode", C.[CountryId] AS "MDMCountryCode", C.[Active] AS "MDMActive", A.[EffectiveEndTime]
FROM
  [Integrations].[acostamdm].[MasterDataMapping] A
  LEFT JOIN [QTrax].[dbo].[Clients] B ON A.[EntityId] = B.[CID]
  LEFT JOIN [Integrations].[acostamdm].[Client] C ON A.[MappedId] = C.[Id]
WHERE
  A.[EntityType] = 'Client' AND A.[MappedType] = 'Acosta Client' AND A.[IsActive] = 1 AND B.[CID] IS NOT NULL
ORDER BY B.[CName]