I have tried countless ways to make this SQL query work, using different date formats, different filters in WHERE clause, ensuring the DE has the correct fields with data types, etc. but I cannot get this query to output results. Always outputs system error.
Essentially, I want to be able to see all subscribers who were sent an email, and see whether or not it was sent, opened, clicked, bounced, etc. Best case scenario would be for me to be able to filter the data based on a specific email, but I have tried EmailID AND EmailName from the Job Data View and it outputs an error as well.
For context, we use single send journeys or multi-step journeys since we want to send tracking data to SFDC, so we also add in journey_name as well for debug/QA.
SELECT
s.SubscriberKey AS subscriber_key
, sub.EmailAddress AS email_address
, sub.Status AS sub_status
, j.JourneyName AS journey_name
, job.EmailName AS email_name
, job.EmailID AS email_id
, s.EventDate AS email_sent_date
, job.DeliveredTime AS job_delivery_date
, o.EventDate AS email_open_date
, c.EventDate AS email_click_date
, b.EventDate AS email_bounce_date
, b.BounceCategory AS bounce_category
, b.BounceSubcategory AS bounce_subcat
, b.SMTPBounceReason AS bounce_reason
, b.BounceType AS bounce_type
, u.EventDate AS unsub_date
FROM _Sent AS s
LEFT JOIN _Job AS job
ON job.JobID = s.JobID
LEFT JOIN _Open AS o
ON o.JobID = s.JobID
AND o.ListID = s.ListID
AND o.BatchID = s.BatchID
AND o.SubscriberID = s.SubscriberID
AND o.IsUnique = 1
LEFT JOIN _Click AS c
ON s.JobID = c.JobID
AND c.ListID = s.ListID
AND c.BatchID = s.BatchID
AND c.SubscriberID = s.SubscriberID
AND c.IsUnique = 1
LEFT JOIN _Bounce AS b
ON s.JobID = b.JobID
AND b.ListID = s.ListID
AND b.BatchID = s.BatchID
AND b.SubscriberID = s.SubscriberID
AND b.IsUnique = 1
LEFT JOIN _Unsubscribe AS u
ON s.JobID = u.JobID
AND u.ListID = s.ListID
AND u.BatchID = s.BatchID
AND u.SubscriberID = s.SubscriberID
AND u.IsUnique = 1
LEFT JOIN _JourneyActivity AS ja
ON ja.JourneyActivityObjectID = s.TriggererSendDefinitionObjectID
LEFT JOIN _Journey AS j
ON j.VersionID = ja.VersionID
LEFT JOIN _Subscribers AS sub
ON sub.SubscriberKey = s.SubscriberKey
WHERE s.EventDate >= DATEADD(DAY,-30, GETDATE())