这个SQL代码是否在程序上运行?

时间:2015-09-22 08:28:51

标签: sql tsql

我正在尝试生成一批单独的报告并重命名它们。一些报告被命名为以下报告,其他报告正在生成两次。

这段SQL代码是否会像过程语言一样逐行运行?

        BEGIN
            --Execute the report
            EXEC ReportServer.dbo.AddEvent @EventType='TimedSubscription', @EventData=  'eca9df5f-270b-4460-a912-360cfd73a476';
            WAITFOR DELAY '00:00:10';
            -- Update processed_reports table once SSRS has executed
            UPDATE [ARCHIVER].[dbo].[test_processed_reports] 
            SET [test_processed_reports].[report_status] = 'processed', [test_processed_reports].[time_stamp] = GETDATE()
            WHERE batch_serial_no = @batch_counter 
            WAITFOR DELAY '00:00:02';
            -- Rename reports
            EXEC [dbo].[sp_ReplaceFileOrDirNames] @batch_counter,'C:\Reports' ,'Main_Report.pdf';
            WAITFOR DELAY '00:00:02';           
        END 

例如它:执行ReportServer作业,等待10秒,更新已处理报告表,等待2秒,然后重命名报告,然后等待2秒。

1 个答案:

答案 0 :(得分:-1)

BEGIN             声明@SQL nvarchar(max)

        set @SQL ='
        EXEC <SPNAME>  
        WAITFOR DELAY ''00:00:10''';                        
        exec (@SQL) 

       set @SQL ='
             UPDATE [ARCHIVER].[dbo].[test_processed_reports] 
        SET [test_processed_reports].[report_status] = ''processed'', [test_processed_reports].[time_stamp] = GETDATE()
        WHERE batch_serial_no = @batch_counter 
        WAITFOR DELAY ''00:00:02''';                        
        exec (@SQL)   


      set @SQL ='
        EXEC <SPNAME> 
        WAITFOR DELAY ''00:00:2''';                        
        exec (@chvSQL)