Given a table containing 'CompanyName'
, 'ContractExpirationDate'
, and 'EmailAlertAddress'
where there may be more than one ContractExpirationDate
on the same day, i.e. More than one company's contract may expires on the same day.
And, each company has a different address for EmailAlertAddress
. I.e. Company ABC alerts go to ABC@domain.com; Company XYZ alerts go to XYZ@domain.com.
Company ABC 08/13/2016 ABC@domain.com
Company DEF 11/31/2017 DEF@domain.com
Company GHI 12/31/2017 GHI@domain.com
Company KLM 01/31/2018 KLM@domain.com
Company NOP 02/31/2018 NOP@domain.com
Company XYZ 08/13/2016 XYZ@domain.com
I need to check all the records daily for any that are expiring in 90, 60, and 30 days. (Since I'll check daily and I only want the alert to go out one time for each period I'll use "WHERE ExpirationDate = CONVERT(VARCHAR,GetDate() + 90, 101)"
so "="
not ">="
Just clarifying there.)
What I can't puzzle out is how to send the alert to only the appropriate email address for each company if more than one expire on the same date.
Say, step through the ones expiring that day and send alert ABC for Company ABC to ABC@domain.com and send alert XYZ for Company XYZ to XYZ@domain.com, say 90 days before the day they both expire.