|
| 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