I am creating an email alert system so when a new ad is posted within a certain metro area, emails will be sent out to those that have subscribed to that metro area's alert.
Users can subscribe to multiple metro areas. I want to send one email to each subscriber which contains all the alerts for multiple metro areas.
I can write a query just fine for returning all the ads that were posted the day before (emails sent out 3AM in the morning), see below:
And I can write another query that returns all the alerts based off the first query's metro area(s):
I am having a hard time trying to figure out how to loop through the emails and providing the address of each new ad:
My guess is to JOIN the two queries some how, but I am at a loss on how to do that for this type of email output - any ideas?
Users can subscribe to multiple metro areas. I want to send one email to each subscriber which contains all the alerts for multiple metro areas.
I can write a query just fine for returning all the ads that were posted the day before (emails sent out 3AM in the morning), see below:
Code:
"GetNewAds" Query
SELECT Parameter.BeginDate, Parameter.listingFK, Parameter.status, Listing.listingId, Listing.address, Listing.metroFk
FROM Listing INNER JOIN Parameter ON Listing.ListingId = Parameter.listingFk
WHERE BeginDate = #yesterday#
And I can write another query that returns all the alerts based off the first query's metro area(s):
Code:
"GetAlert" Query
SELECT Alerts.acctFk, Alerts.metroFk, Account.acctId, Account.email, Account.nameFull
FROM Alerts INNER JOIN Account ON Alerts.acctFk = Account.acctId
WHERE Alerts.metroFk = '#GetNewAds.metroFk#'
I am having a hard time trying to figure out how to loop through the emails and providing the address of each new ad:
Code:
-- loop through the "GetAlert" query --
send email to address from GetAlert query
-- 2nd loop --
within email include all new ads from 1st metro area
-- end 2nd loop --
-- 3rd loop --
within email include all new ads from 2st metro area
-- end 3rd loop --
etc.
-- end loop --
My guess is to JOIN the two queries some how, but I am at a loss on how to do that for this type of email output - any ideas?