Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

XP_Sendmail @Query Expand / Collapse
Author
Message
Posted Thursday, October 15, 2009 6:41 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 17, 2011 8:33 PM
Points: 10, 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
Post #803899
Posted Thursday, October 15, 2009 7:26 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 17, 2011 8:33 PM
Points: 10, Visits: 62
I work out my error:

'SELECT ID, filed2 FROM Mydb.dbo.Mytbl WHERE ID =' + @TblID
Post #803907
Posted Thursday, October 15, 2009 7:40 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 9:14 AM
Points: 9,294, Visits: 9,483
Heh. Glad we could help.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #803910
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse