Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:51:57+00:00 2026-06-12T08:51:57+00:00

I have a job: RunProcedures It has steps: Step 1: Do Something Step 2:

  • 0

I have a job:

RunProcedures

It has steps:

Step 1: Do Something
Step 2: Do something Else
Step 3: Email

In step 3, I have:

EXEC spSendSuccessEmail -- and here's where I want to pass the job name.

Here’s the code for the stored procedure above:

ALTER PROCEDURE [dbo].[spSendSuccessEmail] @JobName VARCHAR(30)
AS 
BEGIN
    SET NOCOUNT ON;

    DECLARE @EmailBody VARCHAR(50)

    SET @EmailBody = @JobName + ' ran successfully'

    BEGIN TRY
        EXEC msdb.dbo.sp_send_dbmail 
            @profile_name = 'DBTeam',
            @recipients = 'user@universe.com',
            @copy_recipients = 'user2@universe.com',
            @subject = 'Process Complete',
            @body = @EmailBody,
            @importance = 'Normal',
            @sensitivity = 'Normal';
    END TRY
    BEGIN CATCH
        EXEC spGetDatabaseErrorInfo
    END CATCH           
END

How do I pass to this stored procedure the name of the job it’s in?

I read on tokens but I’m a little confused on how to accomplish this task.

Can anyone give me a hand?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:51:58+00:00Added an answer on June 12, 2026 at 8:51 am

    UPDATE
    I did some testing and for some versions of SQL Server(2005 sp1 and beyond), you’ll have to escape the Token. I’ve added the escape command to the code below.

    $(JOBID) is the token you want to use, and you can query from msdb..sysjobs to find the job name.

    For sql server 2005 sp1 and beyond:

    declare @jobName varchar(100)
    
    select @jobName = name from msdb..sysjobs where job_id = $(ESCAPE_NONE(JOBID))
    
    exec spSendSuccessEamil @jobName
    

    For sql server 2005 and earlier:

    declare @jobName varchar(100)
    
    select @jobName = name from msdb..sysjobs where job_id = $(JOBID)
    
    exec spSendSuccessEamil @jobName
    

    Just use one of these as your command text within the 3rd step of your job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a job list. Each job has its own run time. They need
I have a job (scheduled by delayed_job ) that sends an email when a
I have a job running under Hudson that has not progressed from Started by
I have a Job model which can have many attachments. The Attachment model has
I have a Job setup in SQL Server 2008 which sends a notification email
I have a job application form where people fill in their name and contact
I have a job with name Myjob.java under package com.example.jobs . This class is
I have a Job class. Here's a simplified version with some sample jobs: class
I have a job that has to run multiple times with different job parameters.
I have a job running using Hadoop 0.20 on 32 spot instances. It has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.