我想在命令参数中使用路径(E:\Ball.bak)作为变量,有什么办法吗?
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Backup',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0,
@subsystem=N'TSQL',
@command=N'"use dbname
go
BACKUP DATABASE [BasketBall] TO DISK =N''E:\Ball.bak''
WITH INIT , NOUNLOAD , NAME = N''backup'', NOSKIP , STATS = 10, NOFORMAT"',
@database_name=N'master',
@flags=0
你可以准备 @command
分别作为一个变量,然后可以直接使用该变量。
试试下面的方法。
declare @path varchar(100) = 'e:\test\ '
declare @cmd nvarchar(max) = N'use dbname
go
BACKUP DATABASE [BasketBall] TO DISK =N'''+@Path+'''
WITH INIT , NOUNLOAD , NAME = N''backup'', NOSKIP , STATS = 10, NOFORMAT'
print @cmd
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Backup',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0,
@subsystem=N'TSQL',
@command=@cmd,
@database_name=N'master',
@flags=0