home *** CD-ROM | disk | FTP | other *** search
/ moodle.waes.ac.uk / moodle.waes.ac.uk.zip / moodle.waes.ac.uk / TMG / SP1-TMG-KB981324-AMD64-ENU.msp / PCW_CAB_SHFx2 / F2143_msfpcui.dll / BINARY / 25490 < prev    next >
Text File  |  2010-06-15  |  4KB  |  104 lines

  1. CREATE PROCEDURE [dbo].[ISA_spTopWebUsersRDL]
  2.     @FromDate datetime,
  3.     @ToDate datetime,
  4.     @ReportType varchar(10),
  5.     @TopCount int,
  6.     @SortOrder varchar(100)
  7. AS
  8. BEGIN
  9.     DECLARE @SummTableName varchar(100)
  10.     SET @SummTableName = dbo.fnGetSummaryTableName('tblUserSummary', @FromDate, @ToDate, @ReportType)
  11.     DECLARE @OrderColumn varchar(100)
  12.     SET @OrderColumn =
  13.             CASE
  14.                 WHEN @SortOrder = 'Requests' THEN 'Requests'
  15.                 WHEN @SortOrder = 'BytesIn' THEN 'BytesIn'
  16.                 WHEN @SortOrder = 'BytesOut' THEN 'BytesOut'
  17.                 ELSE 'TotalBytes'
  18.             END;
  19.     CREATE TABLE #Table1
  20.     (
  21.         UserName nvarchar(514),
  22.         Requests bigint,
  23.         BytesIn bigint,
  24.         BytesOut bigint,
  25.         TotalBytes bigint
  26.     )
  27.     IF OBJECT_ID (@SummTableName, 'u') IS NOT NULL
  28.     BEGIN
  29.         DECLARE @strQuery varchar(8000)
  30.         SET @strQuery =
  31.         'SELECT
  32.             [UserName] ,
  33.             SUM([WebRequests]) AS Requests,
  34.             SUM([WebBytesIn]) AS BytesIn,
  35.             SUM([WebBytesOut]) AS BytesOut,
  36.             SUM([WebTotalBytes]) AS TotalBytes
  37.         FROM ' + @SummTableName + '
  38.         WHERE
  39.             [WebRequests] <>0 AND
  40.             ([date] >= ' + QUOTENAME(CONVERT(varchar, @FromDate, 126),CHAR(39)) + ' AND [date] <= ' + QUOTENAME(CONVERT(varchar, @ToDate, 126),CHAR(39)) + ')
  41.         GROUP BY
  42.             [UserName]
  43.         ORDER BY ' + QUOTENAME(@OrderColumn) + ' DESC;
  44.         '
  45.         INSERT #Table1
  46.         EXEC(@strQuery)
  47.     END
  48.     CREATE TABLE #Table2
  49.     (
  50.         UserName nvarchar(514),
  51.         Requests bigint,
  52.         BytesIn bigint,
  53.         BytesOut bigint,
  54.         TotalBytes bigint
  55.     )
  56.     INSERT INTO #Table2
  57.     SELECT TOP(@TopCount)
  58.         [UserName] AS UserName,
  59.         [Requests] AS Requests,
  60.         [BytesIn] AS BytesIn,
  61.         [BytesOut] AS BytesOut,
  62.         [TotalBytes] AS TotalBytes
  63.     FROM #Table1
  64.     WHERE [UserName] != N'{[23124]}'
  65.     INSERT INTO #Table2
  66.     SELECT
  67.        N'{[23124]}' As UserName,
  68.         SUM(Requests) AS Requests,
  69.         SUM([BytesIn]) AS BytesIn,
  70.         SUM([BytesOut]) AS BytesIn,
  71.         SUM([TotalBytes]) AS TotalBytes
  72.     FROM #Table1 t1
  73.     WHERE NOT EXISTS
  74.         (SELECT * FROM #Table2 t2
  75.          WHERE t1.UserName = t2.UserName)
  76.     DECLARE @TotalRequests bigint
  77.     SET @TotalRequests = (SELECT SUM(Requests) FROM #Table2 )
  78.     IF (@TotalRequests = 0)
  79.         SET @TotalRequests = 1
  80.     DECLARE @totalBytes bigint
  81.     SET @totalBytes = (SELECT SUM(TotalBytes) FROM #Table2 )
  82.     IF (@totalBytes = 0)
  83.         SET @totalBytes = 1
  84.     DECLARE @TotalBytesIn bigint
  85.     SET @TotalBytesIn = (SELECT SUM(BytesIn) FROM #Table2)
  86.     IF (@TotalBytesIn = 0)
  87.         SET @TotalBytesIn = 1
  88.     DECLARE @TotalBytesOut bigint
  89.     SET @TotalBytesOut = (SELECT SUM(BytesOut) FROM #Table2)
  90.     IF (@TotalBytesOut = 0)
  91.         SET @TotalBytesOut = 1
  92.     SELECT
  93.         [dbo].[fnUserOrIpAddressToText]([UserName]) AS [UserName],
  94.         [Requests] AS Requests,
  95.         (CAST([Requests] AS decimal) / @TotalRequests) AS RequestRatio,
  96.         [BytesIn] AS BytesIn,
  97.         (CAST([BytesIn] AS decimal) / @TotalBytesIn) AS BytesInRatio,
  98.         [BytesOut] AS BytesOut,
  99.         (CAST([BytesOut] AS decimal) / @TotalBytesOut) AS BytesOutRatio,
  100.         [TotalBytes] AS TotalBytes,
  101.         (CAST([TotalBytes] AS decimal) / @totalBytes) AS TotalByteRatio
  102.     FROM #Table2
  103. END
  104.