Link to home
Start Free TrialLog in
Avatar of saturation
saturation

asked on

SQL e-mail -- loop through returned records

I am trying to send an HTML email with rows of records in an HTML table format.   I have my SELECT statement as well as the SP to send the e-mail, but I have no idea how to loop through the records from the select statement and put them into a table format within SQL.   Help?


select refid, name, person from valerts


EXEC msdb.dbo.sp_send_dbmail
@recipients =N'myemail@gmail.com',@body = 'test',@body_format ='HTML',@subject ='Message Subject',@profile_name ='DatabaseMailProfile'
Avatar of lcohan
lcohan
Flag of Canada image

ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Declare a temp table and store the resultant records in that

Retrieve the recors one-by-one using a cursor and frame thhe HTML

Send that HTML in mail.