I am trying to create a job that, as one of its steps, will kick off a
DTS package. As part of the command parameter, I need to concat a
system variable (@@SERVERNAME) to a constant string. I am receiving an
error about incorrect syntax near the +.
Here is the code for the job step.
-- Add the job steps
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID,
@step_id = 1,
@step_name = N'Import OCC Series Data',
@command = N'DTSRun /F
D:\Databases\Scripts\DTS\ImportOCCSeriesData.dts /A DbName:8=' +
@@SERVERNAME,
@database_name = N'',
@server = N'',
@database_user_name = N'',
@subsystem = N'CmdExec',
@cmdexec_success_code = 0,
@flags = 2,
@retry_attempts = 0,
@retry_interval = 1,
@output_file_name = N'',
@on_success_step_id = 0,
@on_success_action = 3,
@on_fail_step_id = 0,
@on_fail_action = 3
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
If I just try SELECT N'DTSRun /F
D:\Databases\Scripts\DTS\ImportOCCSeriesData.dts /A DbName:8=' +
@@SERVERNAME, everything works fine. I even tried declaring a local
variable named @command and setting it in the select statement, but no
dice.