需要优化存储过程

时间:2016-07-28 10:01:58

标签: stored-procedures

任何人都可以让我知道优化此查询。我已经在输入表上有索引。

ALTER PROCEDURE [dbo].[sp_CTR_ReleaseServicesData_ROQ_UploadJuly5th_Nick]
AS

  IF OBJECT_ID('tempdb..#TempBuildTable') IS NOT NULL
    DROP TABLE #TempBuildTable
  IF OBJECT_ID('tempdb..#TempSingleBuildTable') IS NOT NULL
    DROP TABLE #TempSingleBuildTable
  IF OBJECT_ID('tempdb..#finalBuild') IS NOT NULL
    DROP TABLE #finalBuild
  IF OBJECT_ID('tempdb..#TempBuilds') IS NOT NULL
    DROP TABLE #TempBuilds
  --IF OBJECT_ID('tempdb..#TempDuplicateBuilds') IS NOT NULL drop table  #TempDuplicateBuilds
  --IF OBJECT_ID('tempdb..#TempUniqueBuilds') IS NOT NULL drop table  #TempUniqueBuilds

  /* Get the last 6 months builds to #TempBuilds Table*/
  SELECT
    * INTO #TempBuilds
  FROM (SELECT DISTINCT
    ROW_NUMBER() OVER (ORDER BY MIN(CreatedDateUTC)) AS Inx,
    BuildNumberV2,
    MIN(CreatedDateUTC) AS MinCreatedDateTime,
    MAX(CreatedDateUTC) AS MaxCreatedDateTime,
    DATEDIFF(HOUR, MIN(CreatedDateUTC), MAX(CreatedDateUTC)) AS TimeBetweenFirstLastFile
  FROM ReleaseServicesData_Test_Nick WITH (NOLOCK)
  WHERE ISNUMERIC(REPLACE(BuildNumberV2, '.', '')) = 1
  AND BuildNumberV2 LIKE '%[0-9]%'
  AND BuildNumberV2 LIKE '%.%'
  AND CreatedDateUTC > DATEADD(MONTH, -6, DATEADD(DD, -DATEPART(DD, GETDATE()) + 1, CAST(GETDATE() AS date)))
  AND
  --BuildNumberV2 = '16.0.7129.6926' AND
  RequestStatus = 'Released'
  GROUP BY BuildNumberV2) AS TempBuilds
  --SELECT * from #TempBuilds


  DECLARE @tempBuildLoopCounter int,
          @tempBuildCount int
  DECLARE @tempBuildNumber varchar(100)
  SELECT
    @tempBuildCount = COUNT(*)
  FROM #TempBuilds
  SET @tempBuildLoopCounter = 1


  DECLARE @MaxReplicationPubKeySingapore varchar(100),
          @MaxReplicationTimeSingapore int
  DECLARE @MaxReplicationPubKeyDublin varchar(100),
          @MaxReplicationTimeDublin int
  DECLARE @MaxReplicationPubKeyPR varchar(100),
          @MaxReplicationTimePR int
  DECLARE @MaxReplicationPubKeyCO1 varchar(100),
          @MaxReplicationTimeCO1 int
  DECLARE @MaxPubKeyUpload varchar(100),
          @MaxTimeUpload int
  DECLARE @MaxPubKeyScan varchar(100),
          @MaxTimeScan int

  WHILE (@tempBuildLoopCounter <= @tempBuildCount)
  BEGIN
    SELECT
      @tempBuildNumber = BuildNumberV2
    FROM #TempBuilds
    WHERE Inx = @tempBuildLoopCounter
    PRINT @tempBuildNumber
    PRINT @tempBuildLoopCounter


    DECLARE @tempSingleBuildCount int,
            @tempCounter int
    DECLARE @tempCreatedTime datetime,
            @tempCreatedTimetoCompare datetime
    DECLARE @tempBuildCounter varchar(10)
    SET @tempCounter = 1
    SET @tempBuildCounter = 0

    IF OBJECT_ID('tempdb..#TempSingleBuildTable') IS NOT NULL
      DROP TABLE #TempSingleBuildTable
    SELECT
      * INTO #TempSingleBuildTable
    FROM (SELECT
      0 AS Inx,
      BuildNumberV2,
      CreatedDateUTC,
      DublinReplicationEndTime,
      DublinReplicationStartTime,
      FileSizeInMB,
      FileUploadEndTimeUTC,
      FileUploadStartTime,
      FileUploadEndTime,
      FileUploadStartTimeUTC,
      ImportCopyEndTime,
      PreVaultEndTimeUTC,
      PublisherKey,
      PuertoRicoReplicationEndTime,
      PuertoRicoReplicationStartTime,
      RedmondReplicationEndTime,
      RedmondReplicationStartTime,
      RequestStatus,
      ROQDUBCompletionTimeUTC,
      ROQMOPRCompletionTimeUTC,
      ROQScanEndTimeUTC,
      ROQScanStartTimeUTC,
      ROQSINCompletionTimeUTC,
      ROQUSOCCompletionTimeUTC,
      SingaporeReplicationEndTime,
      SingaporeReplicationStartTime
    FROM ReleaseServicesData_Test_Nick WITH (NOLOCK)
    WHERE BuildNumberV2 = @tempBuildNumber) AS TempSingleBuildTable;

    WITH cte
    AS (SELECT
      Inx,
      ROW_NUMBER() OVER (ORDER BY CreatedDateUTC) AS RowNumber
    FROM #TempSingleBuildTable)
    UPDATE cte
    SET Inx = RowNumber;

    SELECT
      @tempSingleBuildCount = COUNT(*)
    FROM #TempSingleBuildTable
    WHILE (@tempCounter <= @tempSingleBuildCount)
    BEGIN

      SELECT
        @tempCreatedTime = CreatedDateUTC,
        @tempBuildNumber = BuildNumberV2
      FROM #TempSingleBuildTable
      WHERE Inx = @tempCounter
      SELECT
        @tempCreatedTimetoCompare = CreatedDateUTC
      FROM #TempSingleBuildTable
      WHERE Inx = @tempCounter + 1
      IF (DATEDIFF(HOUR, @tempCreatedTime, @tempCreatedTimetoCompare) <= 2)
      BEGIN
        IF (@tempBuildCounter = 0)
          UPDATE #TempSingleBuildTable
          SET BuildNumberV2 = @tempBuildNumber
          WHERE Inx = @tempCounter
        ELSE
          UPDATE #TempSingleBuildTable
          SET BuildNumberV2 = @tempBuildNumber + '_D' + @tempBuildCounter
          WHERE Inx = @tempCounter
      END
      ELSE
      BEGIN

        IF (@tempBuildCounter = 0)
          UPDATE #TempSingleBuildTable
          SET BuildNumberV2 = @tempBuildNumber
          WHERE Inx = @tempCounter
        ELSE
          UPDATE #TempSingleBuildTable
          SET BuildNumberV2 = @tempBuildNumber + '_D' + @tempBuildCounter
          WHERE Inx = @tempCounter

        SET @tempBuildCounter = @tempBuildCounter + 1
      END

      SET @tempCounter = @tempCounter + 1;
    END
    --select distinct BuildNumber from #TempSingleBuildTable
    --SELECT CreatedDateUTC,BuildNumberV2,* FROM #TempSingleBuildTable order by Inx;
    IF (@tempBuildLoopCounter = 1)
    BEGIN
      SELECT
        * INTO #finalBuild
      FROM (SELECT
        TSB.BuildNumberV2
        --,convert(date, CreatedDateUTC) as CreatedDateUTC  
        ,
        MIN(FileUploadStartTimeUTC) AS FileUploadStartTimeUTC,
        MAX(FileUploadEndTimeUTC) AS FileUploadEndTimeUTC,
        MIN(CreatedDateUTC) AS MinCreatedDateUTC,
        MAX(RedmondReplicationEndTime) AS RedmondReplicationEndTime,
        MAX(SingaporeReplicationEndTime) AS SingaporeReplicationEndTime,
        MAX(DublinReplicationEndTime) AS DublinReplicationEndTime,
        MAX(ImportCopyEndTime) AS ImportCopyEndTime,
        MAX(PuertoRicoReplicationEndTime) AS PuertoRicoReplicationEndTime,
        MAX(ROQScanEndTimeUTC) AS ROQScanEndTimeUTC,
        MAX(PreVaultEndTimeUTC) AS PreVaultEndTimeUTC,
        MAX(ROQMOPRCompletionTimeUTC) AS ROQMOPRCompletionTimeUTC,
        MAX(ROQUSOCCompletionTimeUTC) AS ROQUSOCCompletionTimeUTC,
        MAX(ROQDUBCompletionTimeUTC) AS ROQDUBCompletionTimeUTC,
        MAX(ROQSINCompletionTimeUTC) AS ROQSINCompletionTimeUTC,
        (SELECT
          MAX(v)
        FROM (VALUES (MAX(RedmondReplicationEndTime)),
        (MAX(SingaporeReplicationEndTime)),
        (MAX(DublinReplicationEndTime)),
        (MAX(ImportCopyEndTime)),
        (MAX(PuertoRicoReplicationEndTime)),
        (MAX(ROQScanEndTimeUTC)),
        (MAX(ROQMOPRCompletionTimeUTC)),
        (MAX(ROQUSOCCompletionTimeUTC)),
        (MAX(ROQDUBCompletionTimeUTC)),
        (MAX(ROQSINCompletionTimeUTC)),
        (MAX(PreVaultEndTimeUTC))
        ) AS value (v))
        AS LastActivityTime,
        MAX(FileSizeInMB) AS FileSizeInMB,
        COUNT(FileSizeInMB) AS FileCount,
        0 AS MaxReplicationTimeSingapore,
        'DummyDummyDummy' AS MaxReplicationPubKeySingapore,
        0 AS MaxReplicationTimeDublin,
        'DummyDummyDummy' AS MaxReplicationPubKeyDublin,
        0 AS MaxReplicationTimePR,
        'DummyDummyDummy' AS MaxReplicationPubKeyPR,
        0 AS MaxReplicationTimeCO1,
        'DummyDummyDummy' AS MaxReplicationPubKeyCO1,
        0 AS MaxTimeUpload,
        'DummyDummyDummy' AS MaxPubKeyUpload,
        0 AS MaxTimeScan,
        'DummyDummyDummy' AS MaxPubKeyScan,
        MAX(FileUploadStartTimeUTC) AS MaxFileUploadStartTimeUTC
      FROM #TempSingleBuildTable TSB
      WHERE --Title not like '%15.%' AND Title like '%Mondo%'
      RequestStatus = 'Released'
      AND CreatedDateUTC > DATEADD(MM, -6, DATEADD(DD, -DATEPART(DD, GETDATE()) + 1, CAST(GETDATE() AS date)))
      GROUP BY TSB.BuildNumberV2
      --HAVING LTRIM(RTRIM(RIGHT(SUBSTRING(Title,0,CHARINDEX('_',Title,0)),14))) != ''
      ORDER BY TSB.BuildNumberV2 OFFSET 0 ROWS) AS temp
    END
    ELSE
    BEGIN
      INSERT INTO #finalBuild
        SELECT
          TSB.BuildNumberV2
          --,convert(date, CreatedDateUTC) as CreatedDateUTC  
          ,
          MIN(FileUploadStartTimeUTC) AS FileUploadStartTimeUTC,
          MAX(FileUploadEndTimeUTC) AS FileUploadEndTimeUTC,
          MIN(CreatedDateUTC) AS MinCreatedDateUTC,
          MAX(RedmondReplicationEndTime) AS RedmondReplicationEndTime,
          MAX(SingaporeReplicationEndTime) AS SingaporeReplicationEndTime,
          MAX(DublinReplicationEndTime) AS DublinReplicationEndTime,
          MAX(ImportCopyEndTime) AS ImportCopyEndTime,
          MAX(PuertoRicoReplicationEndTime) AS PuertoRicoReplicationEndTime,
          MAX(ROQScanEndTimeUTC) AS ROQScanEndTimeUTC,
          MAX(PreVaultEndTimeUTC) AS PreVaultEndTimeUTC,
          MAX(ROQMOPRCompletionTimeUTC) AS ROQMOPRCompletionTimeUTC,
          MAX(ROQUSOCCompletionTimeUTC) AS ROQUSOCCompletionTimeUTC,
          MAX(ROQDUBCompletionTimeUTC) AS ROQDUBCompletionTimeUTC,
          MAX(ROQSINCompletionTimeUTC) AS ROQSINCompletionTimeUTC,
          (SELECT
            MAX(v)
          FROM (VALUES (MAX(RedmondReplicationEndTime)),
          (MAX(SingaporeReplicationEndTime)),
          (MAX(DublinReplicationEndTime)),
          (MAX(ImportCopyEndTime)),
          (MAX(PuertoRicoReplicationEndTime)),
          (MAX(ROQScanEndTimeUTC)),
          (MAX(ROQMOPRCompletionTimeUTC)),
          (MAX(ROQUSOCCompletionTimeUTC)),
          (MAX(ROQDUBCompletionTimeUTC)),
          (MAX(ROQSINCompletionTimeUTC)),
          (MAX(PreVaultEndTimeUTC))
          ) AS value (v))
          AS LastActivityTime,
          MAX(FileSizeInMB) AS FileSizeInMB,
          COUNT(FileSizeInMB) AS FileCount,
          0 AS MaxReplicationTimeSingapore,
          'Dummy' AS MaxReplicationPubKeySingapore,
          0 AS MaxReplicationTimeDublin,
          'Dummy' AS MaxReplicationPubKeyDublin,
          0 AS MaxReplicationTimePR,
          'Dummy' AS MaxReplicationPubKeyPR,
          0 AS MaxReplicationTimeCO1,
          'Dummy' AS MaxReplicationPubKeyCO1,
          0 AS MaxTimeUpload,
          'Dummy' AS MaxPubKeyUpload,
          0 AS MaxTimeScan,
          'Dummy' AS MaxPubKeyScan,
          MAX(FileUploadStartTimeUTC) AS MaxFileUploadStartTimeUTC
        FROM #TempSingleBuildTable TSB
        WHERE --Title not like '%15.%' AND Title like '%Mondo%'
        RequestStatus = 'Released'
        AND CreatedDateUTC > DATEADD(MM, -6, DATEADD(DD, -DATEPART(DD, GETDATE()) + 1, CAST(GETDATE() AS date)))
        GROUP BY TSB.BuildNumberV2
        --HAVING LTRIM(RTRIM(RIGHT(SUBSTRING(Title,0,CHARINDEX('_',Title,0)),14))) != ''
        ORDER BY TSB.BuildNumberV2 OFFSET 0 ROWS
    END

    SET @MaxReplicationTimeSingapore = 0
    SET @MaxReplicationTimeDublin = 0
    SET @MaxReplicationTimePR = 0
    SET @MaxReplicationTimeCO1 = 0
    SET @MaxTimeUpload = 0
    SET @MaxTimeScan = 0

    IF OBJECT_ID('tempdb..#tempDistinctDuplicateBuilds') IS NOT NULL
      DROP TABLE #tempDistinctDuplicateBuilds
    DECLARE @tempDistinctDuplicateBuildCount int,
            @tempDuplicateBuildCount int,
            @tempBuildDuplicateNumber varchar(100)
    SET @tempDistinctDuplicateBuildCount = 1
    SET @tempDuplicateBuildCount = 1
    SET @tempBuildDuplicateNumber = ''

    CREATE TABLE #tempDistinctDuplicateBuilds (
      Id int IDENTITY (1, 1),
      BuildNumber varchar(100)
    )

    INSERT INTO #tempDistinctDuplicateBuilds
      SELECT DISTINCT
        BuildNumberV2
      FROM #TempSingleBuildTable

    SELECT
      @tempDuplicateBuildCount = COUNT(*)
    FROM #tempDistinctDuplicateBuilds

    WHILE (@tempDistinctDuplicateBuildCount <= @tempDuplicateBuildCount)
    BEGIN
      SELECT
        @tempBuildDuplicateNumber = BuildNumber
      FROM #tempDistinctDuplicateBuilds
      WHERE Id = @tempDistinctDuplicateBuildCount
      SELECT TOP 1
        @MaxReplicationPubKeySingapore = PublisherKey,
        @MaxReplicationTimeSingapore = MAX(DATEDIFF(MINUTE, SingaporeReplicationStartTime, SingaporeReplicationEndTime))
      FROM #TempSingleBuildTable
      WHERE BuildNumberV2 = @tempBuildDuplicateNumber
      GROUP BY PublisherKey
      ORDER BY MAX(DATEDIFF(MINUTE, SingaporeReplicationStartTime, SingaporeReplicationEndTime)) DESC
      SELECT TOP 1
        @MaxReplicationPubKeyDublin = PublisherKey,
        @MaxReplicationTimeDublin = MAX(DATEDIFF(MINUTE, DublinReplicationStartTime, DublinReplicationEndTime))
      FROM #TempSingleBuildTable
      WHERE BuildNumberV2 = @tempBuildDuplicateNumber
      GROUP BY PublisherKey
      ORDER BY MAX(DATEDIFF(MINUTE, DublinReplicationStartTime, DublinReplicationEndTime)) DESC
      SELECT TOP 1
        @MaxReplicationPubKeyPR = PublisherKey,
        @MaxReplicationTimePR = MAX(DATEDIFF(MINUTE, PuertoRicoReplicationStartTime, PuertoRicoReplicationEndTime))
      FROM #TempSingleBuildTable
      WHERE BuildNumberV2 = @tempBuildDuplicateNumber
      GROUP BY PublisherKey
      ORDER BY MAX(DATEDIFF(MINUTE, PuertoRicoReplicationStartTime, PuertoRicoReplicationEndTime)) DESC
      SELECT TOP 1
        @MaxReplicationPubKeyCO1 = PublisherKey,
        @MaxReplicationTimeCO1 = MAX(DATEDIFF(MINUTE, RedmondReplicationStartTime, RedmondReplicationEndTime))
      FROM #TempSingleBuildTable
      WHERE BuildNumberV2 = @tempBuildDuplicateNumber
      GROUP BY PublisherKey
      ORDER BY MAX(DATEDIFF(MINUTE, RedmondReplicationStartTime, RedmondReplicationEndTime)) DESC
      SELECT TOP 1
        @MaxPubKeyUpload = PublisherKey,
        @MaxTimeUpload = MAX(DATEDIFF(MINUTE, FileUploadStartTime, FileUploadEndTime))
      FROM #TempSingleBuildTable
      WHERE BuildNumberV2 = @tempBuildDuplicateNumber
      GROUP BY PublisherKey
      ORDER BY MAX(DATEDIFF(MINUTE, FileUploadStartTime, FileUploadEndTime)) DESC
      SELECT TOP 1
        @MaxPubKeyScan = PublisherKey,
        @MaxTimeScan = MAX(DATEDIFF(MINUTE, ROQScanStartTimeUTC, ROQScanEndTimeUTC))
      FROM #TempSingleBuildTable
      WHERE BuildNumberV2 = @tempBuildDuplicateNumber
      GROUP BY PublisherKey
      ORDER BY MAX(DATEDIFF(MINUTE, ROQScanStartTimeUTC, ROQScanEndTimeUTC)) DESC

      UPDATE #finalBuild
      SET MaxReplicationTimeSingapore = @MaxReplicationTimeSingapore,
          MaxReplicationPubKeySingapore = @MaxReplicationPubKeySingapore,
          MaxReplicationTimeDublin = @MaxReplicationTimeDublin,
          MaxReplicationPubKeyDublin = @MaxReplicationPubKeyDublin,
          MaxReplicationTimePR = @MaxReplicationTimePR,
          MaxReplicationPubKeyPR = @MaxReplicationPubKeyPR,
          MaxReplicationTimeCO1 = @MaxReplicationTimeCO1,
          MaxReplicationPubKeyCO1 = @MaxReplicationPubKeyCO1,
          MaxTimeUpload = @MaxTimeUpload,
          MaxPubKeyUpload = @MaxPubKeyUpload,
          MaxTimeScan = @MaxTimeScan,
          MaxPubKeyScan = @MaxPubKeyScan
      WHERE BuildNumberV2 = @tempBuildDuplicateNumber





      PRINT @MaxReplicationTimeSingapore
      PRINT @MaxReplicationTimeDublin
      PRINT @MaxReplicationTimePR
      PRINT @MaxReplicationTimeCO1
      PRINT @MaxTimeUpload
      PRINT @MaxTimeScan

      PRINT @MaxReplicationPubKeySingapore
      PRINT @MaxReplicationPubKeyDublin
      PRINT @MaxReplicationPubKeyPR
      PRINT @MaxReplicationPubKeyCO1
      PRINT @MaxPubKeyUpload
      PRINT @MaxPubKeyScan

      PRINT @tempBuildDuplicateNumber

      SET @tempDistinctDuplicateBuildCount = @tempDistinctDuplicateBuildCount + 1
    END
    IF OBJECT_ID('tempdb..#tempDistinctDuplicateBuilds') IS NOT NULL
      DROP TABLE #tempDistinctDuplicateBuilds


    SET @tempBuildLoopCounter = @tempBuildLoopCounter + 1
  END





  ALTER TABLE #finalBuild
  ADD Id int IDENTITY (1, 1)

  ALTER TABLE #finalBuild
  ADD BuildTime int NULL

  ALTER TABLE #finalBuild
  ADD WhoFinishedLast varchar(100)

  UPDATE #finalBuild
  SET BuildTime = DATEDIFF(MINUTE, MinCreatedDateUTC, LastActivityTime)

  DECLARE @lasttempCount int,
          @lastMaxCount int,
          @whofinishedlastTime datetime,
          @whofinishedlast varchar(30)
  SET @lasttempCount = 1
  SELECT
    @lastMaxCount = MAX(Id)
  FROM #finalBuild

  UPDATE #finalBuild
  SET WhoFinishedLast = ''

  DECLARE @totalUploadTime int
  DECLARE @totalBuildTime int

  WHILE (@lasttempCount <= @lastMaxCount)
  BEGIN
    PRINT 'Upload Update'
    SET @totalBuildTime = 1;
    SET @totalUploadTime = 1;

    -- Check if upload time is more than or equal to half of total time taken
    SELECT
      @totalUploadTime = DATEDIFF(MINUTE, FileUploadStartTimeUTC, FileUploadEndTimeUTC),
      @totalBuildTime = BuildTime
    FROM #finalBuild
    WHERE Id = @lasttempCount

    PRINT @totalUploadTime

    IF (@totalUploadTime >= @totalBuildTime / 2)
    BEGIN
      SET @whofinishedlast = 'Upload'
    END
    ELSE
    BEGIN
      SELECT
        @whofinishedlastTime = LastActivityTime
      FROM #finalBuild
      WHERE BuildNumberV2 = (SELECT
        BuildNumberV2
      FROM #finalBuild
      WHERE Id = @lasttempCount)



      SELECT
        @whofinishedlast =
                          CASE @whofinishedlastTime
                            WHEN PuertoRicoReplicationEndTime THEN 'PR'
                            WHEN DublinReplicationEndTime THEN 'DUBLIN'
                            WHEN RedmondReplicationEndTime THEN 'COLUMBIA'
                            WHEN SingaporeReplicationEndTime THEN 'SINGAPORE'
                            WHEN ROQScanEndTimeUTC THEN 'SCAN'
                            WHEN ROQSINCompletionTimeUTC THEN 'SINGAPORE'
                            WHEN ROQDUBCompletionTimeUTC THEN 'DUBLIN'
                            WHEN PreVaultEndTimeUTC THEN 'PreVAULT'
                            WHEN ROQMOPRCompletionTimeUTC THEN 'PR'
                            WHEN ROQUSOCCompletionTimeUTC THEN 'COLUMBIA'
                            ELSE 'We have a Problem'
                          END
      FROM #finalBuild
      WHERE BuildNumberV2 = (SELECT
        BuildNumberV2
      FROM #finalBuild
      WHERE Id = @lasttempCount)
    END
    UPDATE #finalBuild
    SET WhoFinishedLast = @whofinishedlast
    WHERE Id = @lasttempCount
    AND BuildTime > 300

    SET @lasttempCount = @lasttempCount + 1
  END


  TRUNCATE TABLE BI_CTR_Upload_Test_Nick

  INSERT INTO BI_CTR_Upload_Test_Nick
    SELECT
      Id,
      BuildNumberV2,
      FileUploadStartTimeUTC,
      FileUploadEndTimeUTC,
      MinCreatedDateUTC,
      RedmondReplicationEndTime,
      SingaporeReplicationEndTime,
      DublinReplicationEndTime,
      ImportCopyEndTime,
      PuertoRicoReplicationEndTime,
      ROQScanEndTimeUTC,
      PreVaultEndTimeUTC,
      ROQMOPRCompletionTimeUTC,
      ROQUSOCCompletionTimeUTC,
      ROQDUBCompletionTimeUTC,
      ROQSINCompletionTimeUTC,
      LastActivityTime,
      FileSizeInMB,
      MaxReplicationTimeSingapore,
      MaxReplicationPubKeySingapore,
      MaxReplicationTimeDublin,
      MaxReplicationPubKeyDublin,
      MaxReplicationTimePR,
      MaxReplicationPubKeyPR,
      MaxReplicationTimeCO1,
      MaxReplicationPubKeyCO1,
      MaxTimeUpload,
      MaxPubKeyUpload,
      MaxTimeScan,
      MaxPubKeyScan,
      MaxFileUploadStartTimeUTC,
      FileCount,
      BuildTime,
      WhoFinishedLast
    FROM #finalBuild


  IF OBJECT_ID('tempdb..#TempBuildTable') IS NOT NULL
    DROP TABLE #TempBuildTable
  IF OBJECT_ID('tempdb..#DuplicateBuilds') IS NOT NULL
    DROP TABLE #DuplicateBuilds
  IF OBJECT_ID('tempdb..#finalBuild') IS NOT NULL
    DROP TABLE #finalBuild
  IF OBJECT_ID('tempdb..#TempBuilds') IS NOT NULL
    DROP TABLE #TempBuilds
  IF OBJECT_ID('tempdb..#TempDuplicateBuilds') IS NOT NULL
    DROP TABLE #TempDuplicateBuilds
  IF OBJECT_ID('tempdb..#TempUniqueBuilds') IS NOT NULL
    DROP TABLE #TempUniqueBuilds

0 个答案:

没有答案