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 / 25098 < prev    next >
Text File  |  2010-06-15  |  2KB  |  54 lines

  1. CREATE PROCEDURE [dbo].[ISA_spDroppedUserSummaryMonthly]
  2.     @CurrentMonthFirstDay datetime,
  3.     @CurrentMonthLastDay datetime,
  4.     @LastDailyToKeep datetime,
  5.     @LastMonthlyToKeep datetime
  6. AS
  7. BEGIN
  8.     SET NOCOUNT ON;
  9. -- move dailies to monthlies
  10.     SELECT [UserName] AS [UserName]
  11.           ,SUM([DroppedPackets]) AS [DroppedPackets]
  12.           ,@CurrentMonthFirstDay AS [Date]
  13.     INTO #TableOrig
  14.     FROM dbo.tblDroppedUserSummary_Daily
  15.     WHERE (Date >= @CurrentMonthFirstDay) AND
  16.           (Date <= @CurrentMonthLastDay)
  17.     GROUP BY [UserName]
  18.     -- create #table1 empty table copy
  19.     SELECT TOP(0) * INTO #Table1 FROM #TableOrig
  20.     INSERT INTO #TABLE1
  21.     SELECT *
  22.     FROM (
  23.         SELECT
  24.             [UserName], [DroppedPackets], [Date]
  25.         FROM (
  26.             SELECT
  27.                 [UserName], [DroppedPackets], [Date],
  28.                 ROW_NUMBER() OVER (ORDER BY [DroppedPackets] DESC) AS rownum
  29.                 FROM #TableOrig
  30.                 WHERE [UserName] != N'{[23124]}'
  31.             ) t
  32.         WHERE rownum <= 10000
  33.         ) ttt
  34.     ---- now add tail
  35.     INSERT INTO #TABLE1
  36.     SELECT
  37.         N'{[23124]}', SUM([DroppedPackets]), @CurrentMonthFirstDay
  38.     FROM #TableOrig ttt
  39.     WHERE
  40.         [UserName] IS NOT NULL AND
  41.         NOT EXISTS (SELECT *
  42.                     FROM #Table1
  43.                     WHERE ttt.[UserName] = [UserName])
  44.     INSERT INTO dbo.tblDroppedUserSummary_Monthly
  45.     SELECT *
  46.     FROM #TABLE1
  47. -- cleanup dailies
  48.     DELETE FROM [ISA_RS_Db].[dbo].[tblDroppedUserSummary_Daily]
  49.     WHERE (Date < @LastDailyToKeep)
  50. -- cleanup monthlies
  51.     DELETE FROM [ISA_RS_Db].[dbo].[tblDroppedUserSummary_Monthly]
  52.     WHERE (Date < @LastMonthlyToKeep)
  53. END
  54.