此查询未运行一天,但未循环另一天

时间:2016-09-22 05:26:47

标签: sql sql-server sql-server-2012

DECLARE @StartDate DateTime;
DECLARE @EndDate DateTime;
DECLARE @CurrentDate DateTime;
DECLARE @Status INT;

Set @StartDate = '2016-08-19 00:00:00.000';
Set @EndDate = '2016-08-20 00:00:00.000'
Set @CurrentDate = @StartDate

While (@CurrentDate <= @EndDate)
BEGIN
    UPDATE [dbo].[IntegrationLog]
    SET [CUSTOMER] = @CurrentDate, [PRODUCT] = @CurrentDate,
        [ORDER] = @CurrentDate, [ORDERLINE] = @CurrentDate,
        [DELIVERYNOTE] = @CurrentDate, [DELIVERYNOTEITEM] = @CurrentDate,
        [INVOICE] = @CurrentDate, [INVOICEITEM] = @CurrentDate,
        [WAREHOUSE] = @CurrentDate, [DELIVERYRETURN] = @CurrentDate

    declare @output_execution_id bigint
    exec dbo.Execute_ssis_Package @output_execution_id output

    Set @Status = (SELECT [STATUS] FROM [SSISDB].[internal].[operations]
                   WHERE operation_id = @output_execution_id) 

    While (@Status != 7)
    Begin

        WAITFOR DELAY  '00:00:59';
        CONTINUE;
        IF (@STATUS = 4)
        Break; 
    END
    SET @StartDate = DATEADD(DAY, 1, @StartDate);
End    

1 个答案:

答案 0 :(得分:0)

DECLARE @StartDate DateTime;
DECLARE @EndDate DateTime;
DECLARE @CurrentDate DateTime;
DECLARE @Status INT;

Set @StartDate = '2016-08-19 00:00:00.000';
Set @EndDate = '2016-08-20 00:00:00.000'
Set @CurrentDate = @StartDate

While (@CurrentDate <= @EndDate)
BEGIN
   UPDATE [dbo].[IntegrationLog] SET [CUSTOMER] = @CurrentDate,[PRODUCT] = @CurrentDate,[ORDER] = @CurrentDate,[ORDERLINE] = @CurrentDate,
   [DELIVERYNOTE] = @CurrentDate,[DELIVERYNOTEITEM] = @CurrentDate,[INVOICE] = @CurrentDate,[INVOICEITEM] = @CurrentDate,
   [WAREHOUSE] = @CurrentDate, [DELIVERYRETURN] = @CurrentDate

   declare @output_execution_id bigint
   exec dbo.Execute_ssis_Package @output_execution_id output

   Set @Status = (SELECT [STATUS] FROM [SSISDB].[internal].[operations] WHERE operation_id = @output_execution_id) 

   While (@Status != 7)  -
   Begin

   WAITFOR DELAY  '00:00:59';
   CONTINUE;
   IF (@STATUS = 4)
   Break; 
   END
SET @CurrentDate =@CurrentDate+1;
End