-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathReport_Snapshots.sql
41 lines (36 loc) · 1.83 KB
/
Report_Snapshots.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
CREATE PROCEDURE [admin].[report_snapshots]
(
@ReportName AS NVARCHAR(50) = NULL
, @ReportFormat AS NVARCHAR(50) = 'EXCELOPENXML'
)
AS
BEGIN
--EXEC [admin].[report_snapshots] @ReportName = 'Report Name Here', @ReportFormat = 'EXCELOPENXML' --current version of Excel
--EXEC [admin].[report_snapshots] @ReportName = 'Report Name Here', @ReportFormat = 'PDF'
--EXEC [admin].[report_snapshots] @ReportName = NULL, @ReportFormat = 'PDF' --all snapshots for every report
SELECT
[ReportName] = c.[Name]
, [SnaphsotDate] = FORMAT([h].[snapshotdate], 'dd-MMM-yyyy')
, [FileName] = FORMAT([h].[snapshotdate], 'yyyyMMdd')
, [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')
, [Url_Open] = 'http://' + @@SERVERNAME + '/Reports/report' + [c].[path] + '?rs:Snapshot=' + FORMAT([h].[snapshotdate], 'yyyy-MM-ddTHH:mm:ss')
--, [SnapshotDescription] = [s].[DESCRIPTION]
--, [SnapshotEffectiveParams] = [s].[effectiveparams]
--, [SnapshotQueryParams] = [s].[queryparams]
--, [ScheduleName] = [sc].[name]
--, [ScheduleNextRunTime] = [sc].[nextruntime]
FROM
[dbo].[History] AS [h] (NOLOCK)
INNER JOIN [dbo].[SnapshotData] AS [s] (NOLOCK) ON [h].[snapshotdataid] = [s].[snapshotdataid]
INNER JOIN [dbo].[Catalog] AS [c] (NOLOCK) ON [c].[itemid] = [h].[reportid]
INNER JOIN [dbo].[ReportSchedule] AS [rs] (NOLOCK) ON [rs].[reportid] = [h].[reportid]
INNER JOIN [dbo].[Schedule] AS [sc] (NOLOCK) ON [sc].[scheduleid] = [rs].[scheduleid]
WHERE
1=1
AND [rs].[reportaction] = 2 -- Create schedule
AND (@ReportName IS NULL OR [c].[Name] = @ReportName)
ORDER BY
[c].[name]
, [h].[snapshotdate];
END
GO