Skip to content

Instantly share code, notes, and snippets.

@zuzannamj
Created October 25, 2021 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zuzannamj/702529eda6d46586549f41483c13afad to your computer and use it in GitHub Desktop.
Save zuzannamj/702529eda6d46586549f41483c13afad to your computer and use it in GitHub Desktop.
SELECT
contact.Id as SubscriberKey,
contact.Email as EmailAddress,
CASE
WHEN allsub.Status = 'held' THEN 'active'
WHEN allsub.Status = 'bounced' THEN 'active'
ELSE allsub.Status
END as Status
FROM
Contact_Salesforce as contact
RIGHT JOIN
_subscribers as allsub
ON contact.Id = allsub.SubscriberKey
WHERE contact.Email != allsub.EmailAddress
UNION
SELECT
lead.Id as SubscriberKey,
lead.Email as EmailAddress,
CASE
WHEN allsub.Status = 'held' THEN 'active'
WHEN allsub.Status = 'bounced' THEN 'active'
ELSE allsub.Status
END as Status
FROM
Lead_Salesforce as lead
RIGHT JOIN
_subscribers as allsub
ON lead.Id = allsub.SubscriberKey
WHERE lead.Email != allsub.EmailAddress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment