1
- /* '--------------------------------------------------------------------------------------
2
- | Purpose: To search the reporting services execution log
3
- | Note: SQLCmdMode Script
4
- '----------------------------------------------------------------------------------------
1
+ /* '---------------------------------------------------------------------------------------
2
+ ' Purpose: to search the reporting services execution log
3
+ '-----------------------------------------------------------------------------------------
5
4
*/
6
5
6
+ DECLARE @all_value AS VARCHAR (10 )
7
7
DECLARE @LogStatus AS VARCHAR (50 )
8
8
DECLARE @ReportFolder AS VARCHAR (450 )
9
9
DECLARE @ReportName AS VARCHAR (450 )
@@ -12,6 +12,7 @@ DECLARE @GroupByColumn AS VARCHAR(50)
12
12
DECLARE @StartDate AS DATETIME
13
13
DECLARE @EndDate AS DATETIME
14
14
15
+ SET @all_value = ' <ALL>'
15
16
SET @LogStatus = ' <ALL>'
16
17
SET @ReportFolder = ' ...A Report Folder Name...'
17
18
SET @ReportName = ' <ALL>'
@@ -20,92 +21,76 @@ SET @GroupByColumn = 'Report Folder'
20
21
SET @StartDate = NULL
21
22
SET @EndDate = NULL
22
23
23
- :setvar _server " Server1"
24
- :setvar _user " ***username***"
25
- :setvar _password " ***password***"
26
- :setvar _database " ReportServer"
27
- :connect $(_server) - U $(_user) - P $(_password)
28
-
29
- USE [$(_database)];
30
- GO
31
24
32
25
33
26
;WITH
34
- report_execution_log
27
+ report_users
35
28
AS
36
29
(
37
- SELECT
38
- el.*
39
- , SimpleUserName = RIGHT (el .UserName ,(LEN (el .UserName )- CHARINDEX (' \' ,el .UserName )))
40
- , TimeStartDate = CONVERT (DATETIME , CONVERT (VARCHAR (11 ),el .TimeStart ,13 ))
41
- , TotalSecondsFormat = CONVERT (CHAR (8 ),DATEADD (ms,(el .TimeDataRetrieval + el .TimeProcessing + el .TimeRendering ),0 ),108 )
42
- , TimeDataRetrievalFormat = CONVERT (CHAR (8 ),DATEADD (ms,el .TimeDataRetrieval ,0 ),108 )
43
- , TimeProcessingFormat = CONVERT (CHAR (8 ),DATEADD (ms,el .TimeProcessing ,0 ),108 )
44
- , TimeRenderingFormat = CONVERT (CHAR (8 ),DATEADD (ms,el .TimeRendering ,0 ),108 )
45
- , OrderbyDateFormat = CAST (TimeStart AS DATETIME )
46
- FROM
47
- ReportServer .dbo .ExecutionLog el
30
+ SELECT UserID, UserName, SimpleUserName = UPPER (RIGHT (UserName, (LEN (UserName)- CHARINDEX (' \' ,UserName)))) FROM dbo .Users
48
31
)
49
32
,
50
33
report_catalog
51
34
AS
52
35
(
53
36
SELECT
54
- c .ItemID
55
- , c .CreatedById
56
- , c .ModifiedById
57
- , c.[Type]
58
- , c .Name
59
- , c.[Path]
60
- , c.[Description]
61
- , c .Parameter
62
- , ReportCreationDate = CONVERT (DATETIME , CONVERT (VARCHAR (11 ), c .CreationDate , 13 ))
63
- , ReportModifiedDate = CONVERT (DATETIME , CONVERT (VARCHAR (11 ), c .ModifiedDate , 13 ))
64
- , ReportFolder =
65
- CASE
66
- WHEN c .Path = ' /' + c .Name THEN ' '
67
- ELSE SUBSTRING (c .Path , 2 , Len (c .Path )- Len (c .Name )- 2 )
68
- END
69
- , ReportPath = c.[Path]
70
- , UrlPath = ' http://' + Host_Name () + ' /Reports/Pages/Folder.aspx?ItemPath=%2f'
71
- , ReportDefinition = CONVERT (VARCHAR (MAX ),CONVERT (VARBINARY (MAX ),c .content ))
37
+ rpt .ItemID
38
+ , rpt .CreatedById
39
+ , rpt .ModifiedById
40
+ , rpt.[Type]
41
+ , rpt.[Name]
42
+ , ReportName = rpt.[Name]
43
+ , rpt.[Description]
44
+ , rpt .Parameter
45
+ , CreationDate = CONVERT (DATETIME , CONVERT (VARCHAR (11 ), rpt .CreationDate , 13 ))
46
+ , ModifiedDate = CONVERT (DATETIME , CONVERT (VARCHAR (11 ), rpt .ModifiedDate , 13 ))
47
+ , ReportFolder = SUBSTRING (rpt.[Path], 2 , Len (rpt.[Path])- Len (rpt.[Name])- 2 )
48
+ , rpt.[Path]
49
+ , URL_ReportFolder = ' http://' + Host_Name () + ' /Reports/Pages/Report.aspx?ItemPath=%2f' + SUBSTRING (rpt.[Path], 2 , Len (rpt.[Path])- Len (rpt.[Name])- 2 ) + ' &ViewMode=List'
50
+ , URL_Report = ' http://' + Host_Name () + ' /Reports/Pages/Report.aspx?ItemPath=%2f' + SUBSTRING (rpt.[Path], 2 , Len (rpt.[Path])- Len (rpt.[Name])- 2 ) + ' %2f' + rpt.[Name]
51
+ , ReportDefinition = CONVERT (VARCHAR (MAX ), CONVERT (VARBINARY (MAX ), rpt .Content ))
52
+ , HostName = Host_Name ()
72
53
FROM
73
- dbo .Catalog AS c
74
- WHERE c .Type = 2
54
+ dbo .Catalog AS rpt
55
+ WHERE
56
+ 1 = 1
57
+ AND rpt.[Type] = 2
75
58
)
76
59
SELECT
77
- GroupBy1 = CASE
78
- WHEN @GroupByColumn = ' Report Name' THEN c .Name
79
- WHEN @GroupByColumn = ' Report Folder' THEN c .ReportFolder
80
- WHEN @GroupByColumn = ' User Id' THEN el .SimpleUserName
81
- ELSE ' <N/A>' END
82
- , c.[Path]
83
- , c .ReportFolder
84
- , c .Name
85
- , URL_ReportFolder = c .UrlPath + c .ReportFolder + ' &ViewMode=List'
86
- , URL_Report = c .UrlPath + c .ReportFolder + ' %2f' + c .Name
87
- , URL_Report_Filtered = ' http://' + Host_Name () + ' /ReportServer/ReportServer?/' + c .ReportFolder + ' %2f' + c .Name + ' &rs:Command=Render&' + CONVERT (VARCHAR (2000 ), el .Parameters )
88
- , UserName = el .SimpleUserName
89
- , el .Status
60
+ GroupBy1 =
61
+ CASE
62
+ WHEN @GroupByColumn = ' Report Name' THEN rpt .ReportName
63
+ WHEN @GroupByColumn = ' Report Folder' THEN rpt .ReportFolder
64
+ WHEN @GroupByColumn = ' User Id' THEN usr .SimpleUserName
65
+ ELSE ' <N/A>'
66
+ END
67
+ , rpt.[Path]
68
+ , rpt .ReportFolder
69
+ , rpt.[Name]
70
+ , rpt .URL_ReportFolder
71
+ , rpt .URL_Report
72
+ , URL_Report_Filtered = rpt .URL_Report + ' &rs:Command=Render&' + CONVERT (VARCHAR (2000 ), el.[Parameters])
73
+ , UserName = usr .SimpleUserName
74
+ , el.[Status]
90
75
, el .TimeStart
91
76
, el.[RowCount]
92
77
, el .ByteCount
93
- , el .Format
78
+ , el.[ Format]
94
79
, el.[Parameters]
95
- , TotalSeconds = el .TotalSecondsFormat
96
- , TimeDataRetrieval = el .TimeDataRetrievalFormat
97
- , TimeProcessing = el .TimeProcessingFormat
98
- , TimeRendering = el .TimeRenderingFormat
99
- , OrderbyDate = el . OrderbyDateFormat
80
+ , TotalSeconds = CONVERT ( CHAR ( 8 ), DATEADD (ms,( el .TimeDataRetrieval + el . TimeProcessing + el . TimeRendering ), 0 ), 108 )
81
+ , TimeDataRetrieval = CONVERT ( CHAR ( 8 ), DATEADD (ms, el .TimeDataRetrieval , 0 ), 108 )
82
+ , TimeProcessing = CONVERT ( CHAR ( 8 ), DATEADD (ms, el .TimeProcessing , 0 ), 108 )
83
+ , TimeRendering = CONVERT ( CHAR ( 8 ), DATEADD (ms, el .TimeRendering , 0 ), 108 )
84
+ , OrderbyDate = CAST (TimeStart AS DATETIME )
100
85
FROM
101
- report_catalog c
102
- LEFT JOIN report_execution_log el ON el .ReportID = c .ItemID
86
+ report_catalog AS rpt
87
+ LEFT JOIN dbo .ExecutionLog AS el ON el .ReportID = rpt .ItemID
88
+ LEFT JOIN report_users AS usr ON el .UserName = usr .UserName
103
89
WHERE
104
90
1 = 1
105
- AND c .Name NOT IN (' Report Execution Log' ) -- whatever the name of this report is...
106
- AND (@StartDate IS NULL OR el .TimeStartDate >= @StartDate)
107
- AND (@EndDate IS NULL OR el .TimeStartDate <= @EndDate)
108
- AND (' <ALL>' IN (@UserName) OR el .SimpleUserName IN (@UserName))
109
- AND (' <ALL>' IN (@LogStatus) OR el.[Status] IN (@LogStatus))
110
- AND (' <ALL>' IN (@ReportFolder) OR c .ReportFolder IN (@ReportFolder))
111
- AND (' <ALL>' IN (@ReportName) OR c .Name IN (@ReportName))
91
+ AND (@all_value IN (@LogStatus) OR el.[Status] IN (@LogStatus))
92
+ AND (@all_value IN (@ReportFolder) OR rpt .ReportFolder IN (@ReportFolder))
93
+ AND (@all_value IN (@ReportName) OR rpt .ReportName IN (@ReportName))
94
+ AND (@all_value IN (@UserName) OR usr .SimpleUserName IN (@UserName))
95
+ AND (@StartDate IS NULL OR CONVERT (DATETIME , CONVERT (VARCHAR (11 ),el .TimeStart ,13 )) >= @StartDate)
96
+ AND (@EndDate IS NULL OR CONVERT (DATETIME , CONVERT (VARCHAR (11 ),el .TimeStart ,13 )) <= @EndDate)
0 commit comments