I need to write a proc to send out emails - the email list is in a table. One user gets only one email regardless of how many times her/his name appears on the table (I used select distinct). I am able to write a cursor to do this successfully. But I need to modify this so that the user now not only gets an email with the general email text(@body) but also with an attachment which would be the output of a SQL query. This query is what I am having trouble with- in the email table, there are fields "Email Address" and "user id". An example of a few records in the table:
Email Address user id
i have to query such that only one email is sent to each firstname.lastname@example.org and email@example.com. For firstname.lastname@example.org, she should get user id 1, 2 as an attachment. For email@example.com, she should get 3 4 5 as an attachment. How do I modify the existing cursor and/or the @query parameter to do this?
TIA for all the help..