0

I am executing a job from command line (sqlcmd).

EXEC msdb.dbo.sp_start_job @job_name = @job_name

How can I pass a parameter at the time of job execution through the command line.

BIDeveloper
  • 2,628
  • 4
  • 36
  • 51
Pavan Tiwari
  • 3,077
  • 3
  • 31
  • 71
  • Possible duplicate of [Executing the same SSIS Package with different parameters at different time](http://stackoverflow.com/questions/8384850/executing-the-same-ssis-package-with-different-parameters-at-different-time) – BIDeveloper May 16 '16 at 08:09

1 Answers1

0

There is not direct way to pass parameter to "msdb.dbo.sp_start_job"

So we can think indirect way to do something.

You could create a table to hold the parameters, such as:

  CREATE TABLE SQLAgentJobParms
       (job_id uniqueidentifier,
        groupparm int,
        parameter_name nvarchar(100),
        parameter_value nvarchar(100),
         used_datetime datetime NULL);

The groupparm is way to identify a group of parameters intended to go together. One you have used them you can update the used_datetime.

You would then need to write your job to select the necessary values from this table in order to use them as parameters for the steps in your job.

EXEC sp_start_job

sandeep rawat
  • 4,797
  • 1
  • 18
  • 36