Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.20 KB | None | 0 0
  1.  
  2.  
  3. use openaxes
  4.  
  5. declare @investigation int
  6. declare @importBatch int
  7.  
  8. set @investigation = (select top 1 id from investigation (nolock)
  9.                     where status in (4, 30,31,32, 40, 41))
  10. if @investigation is null
  11. begin
  12.    
  13.     set @investigation = (select top 1 id from investigation (nolock)
  14.                     where status in (5,6)
  15.                     order by id desc)
  16.  
  17. end
  18.  
  19. select id, name, status,
  20.     datediff(mi, ProcessingStartDate, isnull(processingenddate, getutcdate())) 'Processing (min)',
  21.     datediff(mi, DataMoveStartDate, DataMoveenddate) 'DataMove (min)',
  22.     datediff(mi, DataCleanupStartDate, DataCleanupEndDate) 'DataCleanup (min)',
  23.     datediff(mi, IndexFlushStartDate, IndexFlushEndDate) 'IndexFlush (min)'
  24. from investigation (nolock) where id = @investigation
  25.  
  26. select * from ImportBatch (nolock) where Investigation = @investigation
  27. set @importBatch = (select top 1 id from ImportBatch (nolock) where investigation = @investigation)
  28.  
  29. select ibf.servername, ibf.status, count(1)
  30. from ImportBatchFile (nolock) ibf
  31. join ImportBatch (nolock) ib on ibf.ImportBatch = ib.id
  32. where ib.investigation = @investigation
  33. group by ibf.servername, ibf.status
  34. order by ibf.servername, ibf.status
  35.  
  36. if (select count(1) from ProcessingItem (nolock)) = 0
  37. begin
  38.  
  39.     select 'QueueItem' 'Table', status, count(1)
  40.     from queueitem (nolock)
  41.     where InvestigationId = @investigation
  42.     group by status
  43.     order by status
  44.  
  45.     SELECT * from InvestigationReport where investigation = @investigation
  46.  
  47. end
  48. else
  49. begin
  50.  
  51.     select servername, status, count(1)
  52.     from ArchiveBatch (nolock)
  53.     where CreatedDate > (select ProcessingStartDate from investigation where id = @investigation)
  54.     group by ServerName, status
  55.     order by ServerName, status
  56.  
  57.  
  58.     select 'ProcessingItem' 'Table', status, servername, count(1)
  59.     from ProcessingItem (nolock)
  60.     group by status, servername
  61.     order by status, servername
  62.  
  63. end
  64. if (SELECT count(1) from ImportBatchFile (nolock)
  65.     where ImportBatch = @importBatch
  66.         and status = 99 and retries < 8
  67.         and errorcode not in (3002, 3004, 3006)) > 0
  68. BEGIN
  69.  
  70.     SELECT *
  71.     from ImportBatchFile (nolock)
  72.     where ImportBatch = @importBatch
  73.         and status = 99 and retries < 8
  74.         and errorcode not in (3002, 3004, 3006)
  75.  
  76. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement