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


XP_Sendmail @Query


XP_Sendmail @Query

Author
Message
ajith.ranjan
ajith.ranjan
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 62
Following is part of TSQL to email the quey as attachemnet. There is a variable parameter in query @TblID. If I replace @TblID with a value (integer) all thing works and send the quey as email attachment. But query does not work with variable parameter.

Declare @email As varchar(70)
Declare @TblID as int

'following values populate from table after update trigger
SELECT @email=SendEmail FROM inserted

SELECT @TblID=TblID FROM inserted

EXEC master..xp_sendmail @recipients = @email,
@query = 'SELECT Field1, Field2 FROM MyDB..dbo.MyTbl WHERE TblID =@tblID;',
@subject = 'Subject ',
@message = 'Message:',
@attach_results = 'TRUE', @width = 250,
@no_output ='FALSE'


Thanks in advance
ajith.ranjan
ajith.ranjan
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 62
I work out my error:

'SELECT ID, filed2 FROM Mydb.dbo.Mytbl WHERE ID =' + @TblID
RBarryYoung
RBarryYoung
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35626 Visits: 9518
Heh. Glad we could help. :-)

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
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