October 2, 2014 at 7:35 am
I am relatively new to programming procedures, but want to program one that will execute the sp_send_dbmail. I have played around a little with the sp_send_dbmail and it works fine if I stipulate the email address in '@recipients =' but what I really want to do is get it to read the recipients email address from a single column, single row table, using a select query. Any help gratefully received.
Dave
October 2, 2014 at 10:12 am
--Build a simple 1 record test table
Select
'Sample@Email.com' as Email
into #TempEmail
--Create a variable to hold the recipient of the email
Declare @recipients varchar(100)
--Populate the variable
Set@recipients = (Select Email from #TempEmail) --Assumes a single row table...add where clause if NOT the case
EXEC msdb.dbo.sp_send_dbmail
@profile_name='YourProfileName', --Change this to your DB mail profile name
@recipients=@recipients,
@subject='Your subject line here........',
@body= 'Test Body copy here.......'
October 3, 2014 at 12:27 am
Perfect, worked first time. Many thanks for your reply, Adaddio
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply