SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Include variable in Email Body


Include variable in Email Body

Author
Message
Minnesota - Viking
Minnesota - Viking
Mr or Mrs. 500
Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)

Group: General Forum Members
Points: 565 Visits: 564
I have a SP that adds a new server to central management studio. It kinds looks like this:


ALTER PROCEDURE [dbo].[XXXXAddServerToCMS_Test]

@NewServerGroupID int,
@NewServerName nvarchar(50),
@@NewServerConnectionInfo nvarchar(50),
@NewServerDescription nvarchar(120)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert

INSERT INTO msdb.dbo.sysmanagement_shared_registered_servers_internal
(Server_Group_ID, name, Server_name, description, Server_Type)
VALUES(@NewServerGroupID, @NewServerName, @@NewServerConnectionInfo, @NewServerDescription,0)



I'm trying to add a email alert to the same like this:


-- Email Confirmation


EXEC sp_send_dbmail default,
@recipients='myemail@mydomain.us',
@subject='CMS on 007 Update',
@body='This is an email confirmation that the following Server/s are now a part of Central Management Server. ' @NewServerConnectionInfo '

Thanks,
SQL SERVER'



I tried both single quotes and double it fails identifying the local variable.

Please suggest an alternative to add the new servername (which is being supplied as input parameter to the SP ) to my email body.

Please do not suggest creating another new SP for the same.


Today is the tomorrow you worried about yesterday:-)

Stuart Davies
Stuart Davies
SSCertifiable
SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)

Group: General Forum Members
Points: 7155 Visits: 4814
Hi,

I've had this problem too. The way that worked for me was to create another variable, populate this with you variable then use that for the email e.g.
declare @Message varchar(500)
set @Message = 'This is an email confirmation that the following Server/s are now a part of Central Management Server. ' + @NewServerConnectionInfo +
'Thanks,
SQL SERVER'
EXEC sp_send_dbmail default,
@recipients='myemail@mydomain.us',
@subject='CMS on 007 Update',
@body=@Message



-------------------------------Posting Data Etiquette - Jeff Moden Smart way to ask a questionThere are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan I would never join a club that would allow me as a member - Groucho Marx
Minnesota - Viking
Minnesota - Viking
Mr or Mrs. 500
Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)Mr or Mrs. 500 (565 reputation)

Group: General Forum Members
Points: 565 Visits: 564
@Stuart

That worked perfectly. Thanks much. Sorry to it took me a while to actually put it in practice.


Today is the tomorrow you worried about yesterday:-)

Stuart Davies
Stuart Davies
SSCertifiable
SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)

Group: General Forum Members
Points: 7155 Visits: 4814
No problem - glad to see you are sorted.

-------------------------------Posting Data Etiquette - Jeff Moden Smart way to ask a questionThere are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan I would never join a club that would allow me as a member - Groucho Marx
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search