Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
NeilG
Aged Yak Warrior
530 Posts |
Posted - 2011-01-26 : 04:29:06
|
Hi hope someone can help me with this,Im trying to send an email via sp_send_cdosysmail, it works fine normally when I enter the values normally, but I'm wanting to add some values through variables it errors.is this possible? here is the example of what i'm trying to createDECLARE @DBName VARCHAR(100),@To Varchar(50)SET @DBName = 'TestingDB'EXEC dbo.sp_send_cdosysmail @To = 'Email@Email.com',@From = 'Email@Email.com',@Subject = 'Test'+@DBName,@Body = 'Error '+@DBName+ 'showing error'+ Error_Message()-----------------------------------------------Learning something new on SQL Server everyday. |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2011-01-26 : 05:41:40
|
You have to set the variable first, you can't concatenate in the call itself, so it would be more like..DECLARE @DBName VARCHAR(100),@To Varchar(50), @Subject VARCHAR(max), @Body varchar(max)SELECT @DBName = 'TestingDB', @Subject = 'Test'+@DBName, @Body = 'Error '+@DBName+ 'showing error' + Error_Message()EXEC dbo.sp_send_cdosysmail @To = 'Email@Email.com',@From = 'Email@Email.com',@Subject = @Subject,@Body = @Body |
 |
|
NeilG
Aged Yak Warrior
530 Posts |
Posted - 2011-01-26 : 06:38:09
|
Excellent thanks for the info, it works like a dream now. |
 |
|
|
|
|
|
|