Number of Performance Samples Per Day (Report Dataset)

image

 /*Number of performance samples per day (trending)
 Jonathan Almquist (https://blogs.technet.com/b/jonathanalmquist/)
 04-08-2011
 */
  
 DECLARE @RowCount AS INT,
     @MGID AS INT,
     @TimeZoneOffset AS INT,
     @OffSetDays AS INT,
     @StartDate AS DATE,
     @EndDate AS DATE
     
 SET @RowCount = 20
 SET @MGID = 1
 SET @TimeZoneOffset = 5
 SET @OffSetDays = 60
 SET @StartDate = DATEADD(hour, @TimeZoneOffset, DATEADD(day, -@OffSetDays, GETDATE()))
 SET @EndDate = DATEADD(hour, @TimeZoneOffset, GETDATE())
  
 SELECT CONVERT(VARCHAR(10), vPD.DateTime, 101) AS 'Date',
         SUM(vPD.SampleCount) AS 'Count'
 FROM  vManagedEntity AS vME INNER JOIN
         Perf.vPerfDaily AS vPD ON vPD.ManagedEntityRowId = vME.ManagedEntityRowId INNER JOIN
         vManagementGroup AS vMG ON vMG.ManagementGroupRowId = vME.ManagementGroupRowId
 WHERE (vMG.ManagementGroupRowId = @MGID) AND (vPD.DateTime BETWEEN @StartDate AND @EndDate)
 group by CONVERT(VARCHAR(10), vPD.DateTime, 101)
 ORDER BY 'Date' DESC

 

Go to main page to download formatted TSQL scripts for all report dataset samples on my blog.