sql server 2008
What I'm trying to do: Looking to see if my sql statement is correct
I need properly read this sql statement and send emails out when the WHERE CLAUSE KICKS IN for a certain date reached.
On a 30 60 90 120 intervals
On the first WHERE clause:
The emails will be sent 30 less than the date_proposal_completed to current date.
Looking at any rows less than 30 days from todays date where "wl_status" IS NULL.
When i send these emails out the "wl_status" gets updated to "emailed30"
AND then a field called "wl_emailed_on" gets updated to the date the email for "emailed30" was sent on. which would be the current date
What i need to happen in the next "OR" part of the WHERE clause
Is send another email only if 60 days from the "wl_emailed_on" to current date
reaches 60 days
wl_emailed_on wl_survey_completed_on wl_status
11/19/2015 8:57:58 AM NULL emailed30 <---- for 60 days this would NOT qualify
9/10/2015 8:57:58 AM NULL emailed30 <---- for 60 days this WOULD qualify
proposal_id, specialist_responsible, customer_name, date_proposal_completed, seller_racf_id,
seller_email, wl_emailed_on, wl_survey_completed_on, wl_status, wl_Q1_answer,
wl_Q2_answer, wl_Q3_answer, wl_Feedback, wl_ReasonLoss
DATEDIFF(day, date_proposal_completed, GETDATE()) <= 30
AND wl_status IS NULL
DATEDIFF(day, wl_emailed_on, GETDATE()) >= 60
AND wl_status = 'emailed30' AND wl_survey_completed_on IS NULL