Executing SQL JOB with Parameter

  • Hi,

    I am working with sql job to run whenever we need and with given name.

    I have a small select statement with where name=@givenname.

    How can I pass the parameter JobName to run this code as sql job without creating this as sp

    Ex:

    Declare @JobName sysname

    SELECT

    job.Originating_Server Server

    ,job.Name JobName

    ,job.job_ID

    FROM

    msdb.dbo.sysjobs_view job

    WHERE

    run_Requested_date is not null

    AND stop_execution_date is null

    and job.name=@JobName

  • One way I've set this up previously is by exporting the job names into a table with a 0/1 in a second column.

    That way the table can be updated to state if that job needs to run (Set column to 1) and when the job polls every minute it would pick up that job name execute the job and reset the status back to 0.

    Hope this helps.

  • You can't pass a parameter to a job. Can I ask why you're reluctant to create a stored procedure? That would be the normal way of doing it.

    John

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply