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
/
25063
< prev
next >
Wrap
Text File
|
2010-06-15
|
5KB
|
128 lines
CREATE PROCEDURE [dbo].[ISA_spSiteSummaryMonthly]
@CurrentMonthFirstDay datetime,
@CurrentMonthLastDay datetime,
@LastDailyToKeep datetime,
@LastMonthlyToKeep datetime
AS
BEGIN
SET NOCOUNT ON;
-- move dailies to monthlies
SELECT
[Site] AS [Site],
SUM([BytesIn]) AS [BytesIn],
SUM([BytesOut]) AS [BytesOut],
SUM([TotalBytes]) AS [TotalBytes],
SUM([Requests]) AS [Requests],
[URLCategoryId] AS [URLCategoryId],
SUM([MalwareIncidents]) AS [MalwareIncidents],
SUM([MalwareInspectionDuration]) AS [MalwareInspectionDuration],
[Action] AS [Action],
@CurrentMonthFirstDay AS [Date]
INTO #TableOrig
FROM dbo.tblSiteSummary_Daily
WHERE (Date >= @CurrentMonthFirstDay) AND
(Date <= @CurrentMonthLastDay)
GROUP BY
[Site],
[UrlCategoryId],
[Action],
CASE
WHEN [MalwareInspectionDuration] = 0 THEN 0
ELSE 1
END
-- create #table1 empty table copy
SELECT TOP(0) * INTO #Table1 FROM #TableOrig
INSERT INTO #Table1
SELECT * FROM #TableOrig WHERE [MalwareIncidents] > 0
DECLARE @SQLString1 nvarchar(2000) =
'SELECT *
FROM (
SELECT
[Site], [BytesIn], [BytesOut], [TotalBytes], [Requests], [URLCategoryId], [MalwareIncidents], [MalwareInspectionDuration], [Action], [Date]
FROM (
SELECT
[Site], [BytesIn], [BytesOut], [TotalBytes], [Requests], [URLCategoryId], [MalwareIncidents], [MalwareInspectionDuration], [Action], [Date],
ROW_NUMBER() OVER (PARTITION BY [Action] ORDER BY '
DECLARE @SQLString2 nvarchar(2000) =
' DESC) AS rownum
FROM #TableOrig
WHERE [Site] != N''{[23124]}'' AND '
DECLARE @SQLString3 nvarchar(2000) =
' > 0 ) t
WHERE rownum <= 5000
) ttt
WHERE [Site] IS NOT NULL
AND [MalwareIncidents] = 0
AND NOT EXISTS (SELECT * FROM #Table1
WHERE ttt.[Site] = [Site] AND
ttt.[BytesIn] = [BytesIn] AND
ttt.[BytesOut] = [BytesOut] AND
ttt.[TotalBytes] = [TotalBytes] AND
ttt.[Requests] = [Requests] AND
ttt.[URLCategoryId] = [URLCategoryId] AND
ttt.[MalwareIncidents] = [MalwareIncidents] AND
ttt.[MalwareInspectionDuration] = [MalwareInspectionDuration] AND
ttt.[Action] = [Action]
)'
DECLARE @SQLString nvarchar(4000)
DECLARE @OrderString nvarchar(200)
SET @OrderString = '[Requests]'
SET @SQLString = @SQLString1 + @OrderString + @SQLString2 + @OrderString + @SQLString3;
INSERT INTO #Table1
EXECUTE(@SQLString)
SET @OrderString = '[TotalBytes]';
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
N'{[23124]}' AS [Site],
SUM([BytesIn]),
SUM([BytesOut]),
SUM([TotalBytes]),
SUM([Requests]),
' ' AS [URLCategoryId],
0 AS [MalwareIncidents],
SUM([MalwareInspectionDuration]),
[Action],
@CurrentMonthFirstDay AS [Date]
FROM #TableOrig ttt
WHERE
[MalwareIncidents] = 0 AND
NOT EXISTS (SELECT *
FROM #Table1
WHERE ttt.[Site] = [Site] AND
ttt.[BytesIn] = [BytesIn] AND
ttt.[BytesOut] = [BytesOut] AND
ttt.[TotalBytes] = [TotalBytes] AND
ttt.[Requests] = [Requests] AND
ttt.[URLCategoryId] = [URLCategoryId] AND
ttt.[MalwareIncidents] = [MalwareIncidents] AND
ttt.[MalwareInspectionDuration] = [MalwareInspectionDuration] AND
ttt.[Action] = [Action])
GROUP BY
[Action],
CASE
WHEN [MalwareInspectionDuration] = 0 THEN 0
ELSE 1
END
INSERT INTO [tblSiteSummary_Monthly]
SELECT *
FROM #TABLE1
-- cleanup dailies
DELETE FROM [ISA_RS_Db].[dbo].[tblSiteSummary_Daily]
WHERE (Date < @LastDailyToKeep)
-- cleanup monthlies
DELETE FROM [ISA_RS_Db].[dbo].[tblSiteSummary_Monthly]
WHERE (Date < @LastMonthlyToKeep)
END