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
/
25108
< prev
next >
Wrap
Text File
|
2010-06-15
|
3KB
|
81 lines
CREATE PROCEDURE [dbo].[ISA_spDestinationSummaryMonthly]
@CurrentMonthFirstDay datetime,
@CurrentMonthLastDay datetime,
@LastDailyToKeep datetime,
@LastMonthlyToKeep datetime
AS
BEGIN
SET NOCOUNT ON;
-- move dailies to monthlies
SELECT [DestinationIP] AS [DestinationIP],
SUM([BytesIn]) AS [BytesIn],
SUM([BytesOut]) AS [BytesOut],
SUM([TotalBytes]) AS [TotalBytes],
SUM([Requests]) AS [Requests],
@CurrentMonthFirstDay AS [Date]
INTO #TableOrig
FROM dbo.tblDestinationSummary_Daily
WHERE (Date >= @CurrentMonthFirstDay) AND
(Date <= @CurrentMonthLastDay)
GROUP BY DestinationIP
-- create #table1 empty table copy
SELECT TOP(0) * INTO #Table1 FROM #TableOrig
-- now calculate the new TOPs
DECLARE @SQLString1 nvarchar(2000) =
'SELECT *
FROM (
SELECT
[DestinationIP], [BytesIn], [BytesOut], [TotalBytes], [Requests], [Date]
FROM (
SELECT
[DestinationIP], [BytesIn], [BytesOut], [TotalBytes], [Requests], [Date],
ROW_NUMBER() OVER (ORDER BY '
DECLARE @SQLString2 nvarchar(2000) =
' DESC) AS rownum
FROM #TableOrig
WHERE [DestinationIP] != ''00000000-0000-0000-0000-000000000000'' AND '
DECLARE @SQLString3 nvarchar(2000) =
' > 0 ) t
WHERE rownum <= 5000
) ttt
WHERE [DestinationIP] IS NOT NULL
AND NOT EXISTS (SELECT * FROM #Table1
WHERE ttt.[DestinationIP] = [DestinationIP])'
DECLARE @SQLString nvarchar(4000)
DECLARE @OrderString nvarchar(200)
SET @OrderString = '[TotalBytes]'
SET @SQLString = @SQLString1 + @OrderString + @SQLString2 + @OrderString + @SQLString3;
PRINT @SQLString
INSERT INTO #Table1
EXECUTE(@SQLString)
SET @OrderString = '[Requests]';
SET @SQLString = @SQLString1 + @OrderString + @SQLString2 + @OrderString + @SQLString3;
INSERT INTO #Table1
EXECUTE(@SQLString)
SET @OrderString = '[BytesIn]';
SET @SQLString = @SQLString1 + @OrderString + @SQLString2 + @OrderString + @SQLString3;
INSERT INTO #Table1
EXECUTE(@SQLString)
SET @OrderString = '[BytesOut]';
SET @SQLString = @SQLString1 + @OrderString + @SQLString2 + @OrderString + @SQLString3;
INSERT INTO #Table1
EXECUTE(@SQLString)
---- now add tail
INSERT INTO #TABLE1
SELECT
'00000000-0000-0000-0000-000000000000', SUM([BytesIn]), SUM([BytesOut]), SUM([TotalBytes]), SUM([Requests]), @CurrentMonthFirstDay
FROM #TableOrig ttt
WHERE
NOT EXISTS (SELECT *
FROM #Table1
WHERE ttt.[DestinationIP] = [DestinationIP])
INSERT INTO dbo.tblDestinationSummary_Monthly
SELECT * FROM #Table1
-- cleanup dailies
DELETE FROM [ISA_RS_Db].[dbo].[tblDestinationSummary_Daily]
WHERE (Date < @LastDailyToKeep)
-- cleanup monthlies
DELETE FROM [ISA_RS_Db].[dbo].[tblDestinationSummary_Monthly]
WHERE (Date < @LastMonthlyToKeep)
END