Skip to content

Commit bd41e14

Browse files
authored
Create ReportSnapshots.sql
1 parent 2decbd6 commit bd41e14

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
CREATE PROCEDURE [admin].[report_snapshots]
2+
(
3+
@ReportName AS NVARCHAR(50) = NULL
4+
, @ReportFormat AS NVARCHAR(50) = 'EXCELOPENXML'
5+
)
6+
AS
7+
8+
BEGIN
9+
10+
--EXEC [admin].[report_snapshots] @ReportName = 'Report Name Here', @ReportFormat = 'EXCELOPENXML' --current version of Excel
11+
--EXEC [admin].[report_snapshots] @ReportName = 'Report Name Here', @ReportFormat = 'PDF'
12+
--EXEC [admin].[report_snapshots] @ReportName = NULL, @ReportFormat = 'PDF' --all snapshots for every report
13+
14+
SELECT
15+
[ReportName] = c.[Name]
16+
, [SnaphsotDate] = FORMAT([h].[snapshotdate], 'dd-MMM-yyyy')
17+
, [FileName] = FORMAT([h].[snapshotdate], 'yyyyMMdd')
18+
, [Url_Download] = 'http://' + @@SERVERNAME + '/ReportServer/Pages/ReportViewer.aspx?' + [c].[path] + '&rs:Command=Render&rs:Format=' + @ReportFormat + '&rs:Snapshot=' + FORMAT([h].[snapshotdate], 'yyyy-MM-ddTHH:mm:ss')
19+
, [Url_Open] = 'http://' + @@SERVERNAME + '/Reports/report' + [c].[path] + '?rs:Snapshot=' + FORMAT([h].[snapshotdate], 'yyyy-MM-ddTHH:mm:ss')
20+
--, [SnapshotDescription] = [s].[DESCRIPTION]
21+
--, [SnapshotEffectiveParams] = [s].[effectiveparams]
22+
--, [SnapshotQueryParams] = [s].[queryparams]
23+
--, [ScheduleName] = [sc].[name]
24+
--, [ScheduleNextRunTime] = [sc].[nextruntime]
25+
FROM
26+
[ReportServer].[dbo].[History] AS [h] (NOLOCK)
27+
INNER JOIN [ReportServer].[dbo].[SnapshotData] AS [s] (NOLOCK) ON [h].[snapshotdataid] = [s].[snapshotdataid]
28+
INNER JOIN [ReportServer].[dbo].[Catalog] AS [c] (NOLOCK) ON [c].[itemid] = [h].[reportid]
29+
INNER JOIN [ReportServer].[dbo].[ReportSchedule] AS [rs] (NOLOCK) ON [rs].[reportid] = [h].[reportid]
30+
INNER JOIN [ReportServer].[dbo].[Schedule] AS [sc] (NOLOCK) ON [sc].[scheduleid] = [rs].[scheduleid]
31+
WHERE
32+
1=1
33+
AND [rs].[reportaction] = 2 -- Create schedule
34+
AND (@ReportName IS NULL OR [c].[Name] = @ReportName)
35+
ORDER BY
36+
[c].[name]
37+
, [h].[snapshotdate];
38+
39+
END
40+
41+
GO

0 commit comments

Comments
 (0)