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
/
25193
< prev
next >
Wrap
Text File
|
2010-06-15
|
5KB
|
127 lines
CREATE PROCEDURE [dbo].[ISA_spTrimArraySiteSummary]
@FromDate datetime,
@ToDate datetime
AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID ('tblSiteSummary_Daily', 'u') IS NULL
RETURN
-- create #table1 empty table copy
SELECT TOP(0) * INTO #Table1 FROM [tblSiteSummary_Daily]
DELETE FROM [tblSiteSummary_Daily]
OUTPUT DELETED.* INTO #Table1
WHERE ([Date] >= @FromDate) AND ([Date] < @ToDate)
SELECT [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],
[Date] AS Date
INTO #TableOrig
FROM #Table1
GROUP BY
[Date],
[Site],
[UrlCategoryId],
[Action],
CASE
WHEN [MalwareInspectionDuration] = 0 THEN 0
ELSE 1
END
TRUNCATE TABLE #Table1
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 [Date], [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] AND
ttt.[Date] = [Date]
)'
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],
[Date]
FROM #TableOrig ttt
WHERE
[Requests] 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] AND
ttt.[Date] = [Date] )
GROUP BY
[Date],
[Action],
CASE
WHEN [MalwareInspectionDuration] = 0 THEN 0
ELSE 1
END
INSERT INTO [tblSiteSummary_Daily]
SELECT *
FROM #TABLE1
END