0

I need an email sent on a specific date, my current query populates a data extension from the difference of days since the users received a particular "email id". What would be the best way to have this query populate a new data ext 1 day before the given date?

SELECT 
  EmailAddress as SubscriberKey
  , EmailAddress
  , first_name
  , last_name
  , registration_date 
FROM Wild_Spirit_12pm h 
WHERE h.EmailAddress IN (
   SELECT s.SubscriberKey   
   FROM _Sent s     
   INNER JOIN _Job j ON s.JobID = j.JobID   
   WHERE j.EmailID = '2457224'
   AND DATEDIFF(Day, s.EventDate, Getdate()) = 1) /* this is where i need it send 1 day before 6/28/16 */
1
  • 1
    It doesn't look like a SOQL query. Please provide more context to the question.
    – Ashwani
    Commented Jun 8, 2016 at 20:50

1 Answer 1

0

Something like this perhaps? Casting the dates as date will set the time portion to midnight.

SELECT 
  h.EmailAddress as SubscriberKey
  , h.EmailAddress
  , h.first_name
  , h.last_name
  , h.registration_date 
FROM Wild_Spirit_12pm h 
WHERE h.EmailAddress IN (
   SELECT s.SubscriberKey   
   FROM _Sent s     
   INNER JOIN _Job j ON (s.JobID = j.JobID)
   WHERE j.EmailID = 2457224 /* emailid is a number */
   AND DATEDIFF(d, cast(s.EventDate as date), cast(Getdate() as date)) = 1 /* was yesterday*/
)

or a more sargable version:

SELECT 
  h.EmailAddress as SubscriberKey
  , h.EmailAddress
  , h.first_name
  , h.last_name
  , h.registration_date 
FROM Wild_Spirit_12pm h 
WHERE h.EmailAddress IN (
   SELECT s.SubscriberKey   
   FROM _Sent s     
   INNER JOIN _Job j ON (s.JobID = j.JobID)
   WHERE j.EmailID = 2457224 /* emailid is a number */
   AND s.eventDate >= convert(date, getDate()-1) 
   and s.eventDate < convert(date, getDate())
)
8
  • so the only way i could set the date to any of my choosing would be to put this query in an automation set to run on that specific date correct? or is there a way to hardcode the date(6/28/16) directly into the query?
    – Angel
    Commented Jun 23, 2016 at 21:21
  • You can hardcode the date if you want. Instead of cast(getDate() as date) you can use cast('2016-06-23' as date). Commented Jun 23, 2016 at 21:24
  • Sweet. Did this work for you? If so, would you checking the check-mark beside my answer? I'd appreciate it. For more information about accepting answers, take a look at our FAQ. Commented Jul 12, 2016 at 14:13
  • there you buddy! thanks for being a great help to the community!
    – Angel
    Commented Jul 14, 2016 at 19:03
  • Hey Adam, I tried the date query between two dates and i keep getting this error, maybe you can help. trying to create a year to date field in a DE. i.imgur.com/mxBRHBb.png This line causes the error : (select count(*) from TenWays_0 where DATEDIFF(Day, Getdate(), EventDate) BETWEEN DATEDIFF(Day, Getdate(), '2016-01-01') AND DATEDIFF(Day, Getdate(), '2016-12-31')) as EOY. thank you!
    – Angel
    Commented Jul 21, 2016 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .