well now you have the desired contents for the email; now it's just a cursor based on that query:
here's part two of the example, where you send individualized emails:
DECLARE
@isql VARCHAR(2000),
@email VARCHAR(64),
@notes VARCHAR(max)
DECLARE c1 CURSOR FOR SELECT Email,Notes From OurBigger_Query_with_FORXML
OPEN c1
FETCH NEXT FROM c1 INTO @email,@notes
WHILE @@FETCH_STATUS <> -1
BEGIN
declare @body1 varchar(4000)
set @body1 = 'This is a Simple Email Example generated on ' + CONVERT( VARCHAR( 20 ), GETDATE(), 113 ) +
' to demonstrate sending a basic notification' + @notes
--this assumes a profile was set as "default", so i don't have to explicitly specify which one to use. else you get this error:
/*
Msg 14636, Level 16, State 1, Procedure sp_send_dbmail, Line 112
No global profile is configured. Specify a profile name in the @profile_name parameter.
*/
EXEC msdb.dbo.sp_send_dbmail
--@profile_name='Stormrage DBMail',
@recipients=@email,
@subject = 'Simple Email Example',
@body = @body1,
@body_format = 'HTML'
--@body_format = 'TEXT'
FETCH NEXT FROM c1 INTO @email,@notes
END
CLOSE c1
DEALLOCATE c1
Lowell