How to send multiple emails from sql server database using sp_send_dbmail procedure -
i have procedure results data table contains 3 columns emails,proposal_type,count(matchestoemail) matches based on proposal_type. have send notification mails 'emails' stating have these many number of matches based on proposal_type. procedure output data this.
emails prop_type matches abc@gmail.com 1 3 abc@gmail.com 2 4 def@gmail.com 3 2
i want mails recipient , remaining 2 columns in body of email additional text. plz me.
thanks
edited
this should work
create proc [dbo].[sendproposalreport] declare rscursor cursor read_only select emails, prop_type, count(matches) matches proposals group emails, prop_type declare @emails nvarchar (100) declare @prop_type int declare @maches int open rscursor fetch next rscursor @emails,@prop_type,@maches while @@fetch_status=0 begin exec msdb.dbo.sp_send_dbmail @recipients = @emails, @subject = 'example email', @body = 'write message here', @profile_name = 'exampleprofile', @attach_query_result_as_file = 1 fetch next rscursor @emails,@prop_type,@maches end close rscursor deallocate rscursor
Comments
Post a Comment