如何在SQL Server中使用脚本计划作业?

时间:2019-07-17 04:08:21

标签: sql sql-server sql-server-2008

在SQL Server中,我没有获得SQL Server代理选项来安排作业,因此我是自动运行该脚本的脚本。我有插入和删除过程的程序。请注意,我想每天4:40 AM执行它

我已经尝试过,但出现此错误

  

信息8146,级别16,状态1,过程Union_BI,第0行[批处理开始第3行]   过程Union_BI没有提供参数和参数。

DECLARE @DynamicTSQLStatement NVARCHAR(MAX); 
SELECT @DynamicTSQLStatement =  STUFF
(
    (       
         SELECT N' UNION ALL SELECT * FROM ' + '[' + SCHEMA_NAME([schema_id]) + '].[' + [name] + ']'
        FROM [sys].[tables]
        WHERE [name] LIKE  'TRNS%9' or  [name] LIKE  'TRNS%20'
        FOR XML PATH(''), TYPE
    ).value('.', 'NVARCHAR(MAX)')
    ,1
    ,10
    ,''
);
Delete from TRNS ; insert into TRNS EXEC sp_executesql  @DynamicTSQLStatement
以上是我的程序     USE Snowman_Attn;     走     EXEC Snowman_Attn.dbo.Union_BI          @job_name = N'Auto Union_BI',         @step_name = N'Step         ,@子系统= N'TSQL'         ,@ database_name ='Snowman_Attn'         ,@ command = N'Exec Union_BI;'         ,@ server_name ='SLL-DSK-046'         ,@ freq_type = 4         ,@ freq_interval = 1         ,@ freq_subday_type = 4         ,@ freq_subday_interval = 60         ,@ freq_recurrence_factor = 1         ,@ schedule_name = N'Auto Union_BI';     GO

它应该在4:40 AM运行我的过程EXEC Snowman_Attn.dbo.Union_BI

1 个答案:

答案 0 :(得分:0)

此复制粘贴脚本是否来自您的数据库? 'Step'之后缺少一个撇号

  USE Snowman_Attn;
GO
EXEC Snowman_Attn.dbo.Union_BI
     @job_name = N'Auto Union_BI', 
    @step_name        = N'Step'
    ,@subsystem        = N'TSQL'
    ,@database_name    = 'Snowman_Attn' 
    ,@command          = N'Exec Union_BI;'
    ,@server_name = 'SLL-DSK-046' 
    ,@freq_type              = 4 
    ,@freq_interval          = 1 
    ,@freq_subday_type       = 4 
    ,@freq_subday_interval   = 60 
    ,@freq_recurrence_factor = 1 
    ,@schedule_name    = N'Auto Union_BI' ; 
GO