Set Based SQL Server sp_send_dbmail Stored Procedure call for a ResultSet of multiple rows -


hello stackoverflow community!

i have query have found difficult find answer in forms.

i have simple stored procedure:

create procedure [dbo].[spsendemail]  @to nvarchar(100),    @subject nvarchar(200), @body nvarchar(max), @fileattachments nvarchar(max) = null  begin  exec  [msdb].[dbo].sp_send_dbmail @profile_name= 'test mail', @recipients=@to,     @subject=@subject, @body=@body, @body_format = 'html', @file_attachments= @fileattachments  end 

i want call result set query each row passing in paramaters required, i.e. @to

a simplified version of result set query, returning 4 columns:

    set rowcount 0 select s.email_address, s.date,s.code,s.description #tempmydetails     contactinfo s 

from table doing following:

    declare @subject nvarchar(200) set @subject = 'my email'  declare @sql nvarchar(max);   set     @sql = n''; select  @sql = @sql + ' exec spsendemail '''      + t.email_address + '''' + ',' + '''' + @subject + ': ' + t.code + '''' + ','     dbo.fndetailsbody(t.code,t.date,t.description) #tempdetails t  exec (@sql);  drop table #tempdetails; 

nb function fndetailsbody() returns nvarchar string of html based on params email.

i have working, sending email each email return in result table, however.

is best / way approach without using while / cursor send email each row?

thanks lot.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -