ElJayWilson
Programmer
I am trying to figure out how to loop through a recordset and call a stored proc (from within a stored proc) to send out emails. We have an SP that will do all the work of sending out emails, I just need some help in modifying my SP to send one email for every record in the recordset.
Here is my query that I am using in my SP currently:
I can use sv.id (Visit ID) to get the email address of the person I need to email.
How would I "loop" through the records to Exec the other SP?
Here is my query that I am using in my SP currently:
Code:
SELECT dbo.ProperCase(st.FirstName)
+ ' ' +
dbo.ProperCase(st.LastName) as [Name]
, sv.id AS [Visit ID]
, aw.Mneumonic AS Mneumonic
, CONVERT(VARCHAR(10)
, sv.visit_date, 101) AS [Visit Date]
, sv.award_fk AS [Award #]
FROM dbo.Scheduled_Visits sv
LEFT JOIN [CHAOS].[dbo].[Awards] aw on aw.AwardNumber = sv.award_fk
AND aw.Mneumonic IS NOT null
RIGHT JOIN dbo.Subjects_tbl st on st.SubjectID= sv.subject_fk
WHERE sv.is_finalized = 0 and sv.visit_date < GETDATE()
GROUP BY aw.Mneumonic,
sv.award_fk,
sv.id,
sv.visit_date,
st.LastName,
st.FirstName
ORDER BY Mneumonic
I can use sv.id (Visit ID) to get the email address of the person I need to email.
How would I "loop" through the records to Exec the other SP?