• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

XP_SENDMAIL trying to put a Variable into the @Query spot

I am trying to put a variable into my @query and It errors out by saying I need to declare it. Here is what I am using:

PROCEDURE dbo.[procExpCert]
@company varchar(50)
AS
BEGIN
    SET NOCOUNT ON
           EXEC Training_Records.dbo.qryExpEmpCerts @company


    IF @@ROWCOUNT > 0
    BEGIN
                DECLARE @body VARCHAR(200)
      DECLARE @strSQL VARCHAR(200)
                SET @body = 'Below is a list of Employees from ' + @company + 'whom have expiring certifications:'
      SET @strSQL = 'EXEC Training_Records.dbo.qryExpEmpCerts ' + @company

        EXEC master..xp_sendmail
            @recipients='thomas.spencer@mf.bz',
            @width = 120,
            @query = @strSQL,
            @message = @body,
            @subject = 'List of Employees whom have certifications expiring soon'

    END
END

I have tried all diffrent ways but can't seem to get it right. Thanks in advance
0
tweeter514
Asked:
tweeter514
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
PROCEDURE dbo.[procExpCert]
@company varchar(50)
AS
BEGIN
    SET NOCOUNT ON
           EXEC Training_Records.dbo.qryExpEmpCerts @company


    IF @@ROWCOUNT > 0
    BEGIN
                DECLARE @body VARCHAR(200)
     DECLARE @strSQL VARCHAR(200)
                SET @body = 'Below is a list of Employees from ' + @company + 'whom have expiring certifications:'
     SET @strSQL = 'EXEC Training_Records.dbo.qryExpEmpCerts ''' + @company + ''''

        EXEC master..xp_sendmail
            @recipients='thomas.spencer@mf.bz',
            @width = 120,
            @query = @strSQL,
            @message = @body,
            @subject = 'List of Employees whom have certifications expiring soon'

    END
END
0
 
tweeter514Author Commented:
Thank you!
0
 
pai_prasadCommented:
i just tried that and it did sent a mail ( to 'thomas.spencer@mf.bz', ) !!!!
i didnt notice the id was tat of some1 else.
0
 
tweeter514Author Commented:
Yea it was my other email address I just got the very long email ;)
0
 
pai_prasadCommented:
sori bout tat... i had used select * from sysobjects...
newayz...i didnt get the error
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now