We help IT Professionals succeed at work.
Get Started

sp_send_dbmail

JoeBo747
JoeBo747 asked
on
1,086 Views
Last Modified: 2012-05-09
Hi
I have configured dbmail on sql server 2008. This works fine but I wish to Pass dynamic data into the mail message. My stored procedure has a variable @mailtxt  and the variable is populated from other variables as below
declare @Mailtxt nvarchar(250)
declare @email nvarchar(70)
declare @Jobnum nvarchar(12)
select @Jobnum = (select DwJobnumber from inserted)
select @email = (SELECT ‘myemail@mycomp.co.uk’)
select @mailtxt  = (select 'User ' + @email + ' has put bad time value in Job ' + @Jobnum)
EXEC msdb.dbo.sp_send_dbmail @profile_name='Tracker_Mail',
@recipients='mail@mycompany.co.uk',
@subject= 'Bad Delivery date' ,
@body = @mailtxt

The mail is sent but without the details in @mailtxt. What is the correct method to pass the values into the mail body?

Regards
JoeBo
Comment
Watch Question
Senior Systems and Integration Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 3 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE