Skip to content

Commit 7d401d7

Browse files
author
Nicolas Molinos
committed
Fully qualified queries with ReportServer database
1 parent b6317c6 commit 7d401d7

File tree

1 file changed

+119
-119
lines changed

1 file changed

+119
-119
lines changed

ServerReports/Subscriptions.rdl

Lines changed: 119 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ SET @Current = '<ALL>'
9999
--, [UrlPath] = 'http://' + Host_Name() + '/Reports/Pages/Folder.aspx?ItemPath=%2f'
100100
--, [ReportDefinition] = CONVERT(VARCHAR(MAX),CONVERT(VARBINARY(MAX), c.[content]))
101101
FROM
102-
dbo.[Catalog] AS c
102+
ReportServer.dbo.[Catalog] AS c
103103
WHERE c.[Type] = 2
104104
)
105105
,
@@ -241,7 +241,7 @@ SET @Current = '<ALL>'
241241
END
242242
--, sc.[RecurrenceType]
243243
FROM
244-
dbo.[Schedule] sc
244+
ReportServer.dbo.[Schedule] sc
245245
LEFT JOIN subscription_days sd ON sc.[DaysOfWeek] = sd.[CodeNbr] AND sd.[GroupName] = 'DayOfWeek'
246246
LEFT JOIN subscription_days AS dom ON sc.[DaysOfMonth] = dom.[CodeNbr] AND dom.[GroupName] = 'DaysOfMonth'
247247
LEFT JOIN subscription_days AS dow ON sc.[DaysOfWeek] = dow.[CodeNbr] AND dow.[GroupName] = 'DaysOfWeek'
@@ -282,129 +282,129 @@ SET @Current = '<ALL>'
282282
, [EmailIncludeLink] = CASE CHARINDEX('<Name>IncludeLink</Name><Value>', s.ExtensionSettings) WHEN 0 THEN '' ELSE SUBSTRING(s.ExtensionSettings, LEN('<Name>IncludeLink</Name><Value>') + CHARINDEX('<Name>IncludeLink</Name><Value>', s.ExtensionSettings), CHARINDEX('</Value>', s.ExtensionSettings, CHARINDEX('<Name>IncludeLink</Name><Value>', s.ExtensionSettings) + 1) - (LEN('<Name>IncludeLink</Name><Value>') + CHARINDEX('<Name>IncludeLink</Name><Value>', s.ExtensionSettings))) END
283283
, [EmailRenderFormat] = CASE CHARINDEX('<Name>RenderFormat</Name><Value>', s.ExtensionSettings) WHEN 0 THEN '' ELSE SUBSTRING(s.ExtensionSettings, LEN('<Name>RenderFormat</Name><Value>') + CHARINDEX('<Name>RenderFormat</Name><Value>', s.ExtensionSettings), CHARINDEX('</Value>', s.ExtensionSettings, CHARINDEX('<Name>RenderFormat</Name><Value>', s.ExtensionSettings) + 1) - (LEN('<Name>RenderFormat</Name><Value>') + CHARINDEX('<Name>RenderFormat</Name><Value>', s.ExtensionSettings))) END
284284
, [EmailPriority] = CASE CHARINDEX('<Name>Priority</Name><Value>', s.ExtensionSettings) WHEN 0 THEN '' ELSE SUBSTRING(s.ExtensionSettings, LEN('<Name>Priority</Name><Value>') + CHARINDEX('<Name>Priority</Name><Value>', s.ExtensionSettings), CHARINDEX('</Value>', s.ExtensionSettings, CHARINDEX('<Name>Priority</Name><Value>', s.ExtensionSettings) + 1) - (LEN('<Name>Priority</Name><Value>') + CHARINDEX('<Name>Priority</Name><Value>', s.ExtensionSettings))) END
285-
, sch.[MinutesInterval]
286-
, sch.[DaysInterval]
287-
, sch.[WeeksInterval]
288-
, sch.[DaysOfWeek]
289-
, sch.[DaysOfMonth]
290-
, sch.[Month]
291-
, sch.[MonthlyWeek]
292-
--, [JobName] = sj.[name]
293-
, sch.[ScheduleName]
294-
, sch.[ScheduleDays]
295-
, sch.[SchDaySun]
296-
, sch.[SchDayMon]
297-
, sch.[SchDayTue]
298-
, sch.[SchDayWed]
299-
, sch.[SchDayThr]
300-
, sch.[SchDayFri]
301-
, sch.[SchDaySat]
302-
, sch.[ScheduleStartDate]
303-
, sch.[ScheduleEndDate]
304-
, sch.[Flags]
305-
, sch.[RecurrenceType]
306-
, sch.[State]
307-
FROM
308-
dbo.[Subscriptions] AS s
309-
LEFT JOIN dbo.[Notifications] AS n ON n.[SubscriptionID] = s.[SubscriptionID] AND s.[Report_OID] = n.[ReportID]
310-
LEFT JOIN dbo.[ReportSchedule] AS rs ON s.[SubscriptionID] = rs.[SubscriptionID]
311-
--LEFT JOIN MSDB.dbo.[sysjobs] AS sj ON sj.[name] = CAST(rs.[ScheduleID] AS VARCHAR(255))
312-
LEFT JOIN subscription_schedule AS sch ON rs.[ScheduleID] = sch.[ScheduleID]
313-
WHERE
314-
1=1
315-
--AND sch.[RecurrenceType] IN(4,5) -- 1 = is one off, 4 = daily, 5 = monthly
316-
--AND s.[EventType] = 'TimedSubscription'
317-
)
318-
SELECT
319-
c.[Name]
320-
, c.[Description]
321-
, c.[Parameter]
322-
, c.[ReportFolder]
323-
, c.[ReportPath]
324-
, [URL_ReportFolder] = c.[UrlPath] + c.[ReportFolder] + '&ViewMode=List'
285+
, sch.[MinutesInterval]
286+
, sch.[DaysInterval]
287+
, sch.[WeeksInterval]
288+
, sch.[DaysOfWeek]
289+
, sch.[DaysOfMonth]
290+
, sch.[Month]
291+
, sch.[MonthlyWeek]
292+
--, [JobName] = sj.[name]
293+
, sch.[ScheduleName]
294+
, sch.[ScheduleDays]
295+
, sch.[SchDaySun]
296+
, sch.[SchDayMon]
297+
, sch.[SchDayTue]
298+
, sch.[SchDayWed]
299+
, sch.[SchDayThr]
300+
, sch.[SchDayFri]
301+
, sch.[SchDaySat]
302+
, sch.[ScheduleStartDate]
303+
, sch.[ScheduleEndDate]
304+
, sch.[Flags]
305+
, sch.[RecurrenceType]
306+
, sch.[State]
307+
FROM
308+
ReportServer.dbo.[Subscriptions] AS s
309+
LEFT JOIN ReportServer.dbo.[Notifications] AS n ON n.[SubscriptionID] = s.[SubscriptionID] AND s.[Report_OID] = n.[ReportID]
310+
LEFT JOIN ReportServer.dbo.[ReportSchedule] AS rs ON s.[SubscriptionID] = rs.[SubscriptionID]
311+
--LEFT JOIN MSDB.dbo.[sysjobs] AS sj ON sj.[name] = CAST(rs.[ScheduleID] AS VARCHAR(255))
312+
LEFT JOIN subscription_schedule AS sch ON rs.[ScheduleID] = sch.[ScheduleID]
313+
WHERE
314+
1=1
315+
--AND sch.[RecurrenceType] IN(4,5) -- 1 = is one off, 4 = daily, 5 = monthly
316+
--AND s.[EventType] = 'TimedSubscription'
317+
)
318+
SELECT
319+
c.[Name]
320+
, c.[Description]
321+
, c.[Parameter]
322+
, c.[ReportFolder]
323+
, c.[ReportPath]
324+
, [URL_ReportFolder] = c.[UrlPath] + c.[ReportFolder] + '&ViewMode=List'
325325
, [URL_Report] = '/Reports/report/' + c.[ReportFolder] + '%2f' + c.[Name]
326326
, [URL] = '/Reports/manage/catalogitem/editsubscription' + c.[ReportPath] + '?id=' + CAST(s.[SubscriptionID] AS VARCHAR(80))
327327
, [URL2] = '/Reports/Pages/Report.aspx?ItemPath=' + c.[ReportPath] + '&SelectedTabId=SubscriptionsTab'
328328
--, [URL_Report] = 'http://' + Host_Name() + '/Reports/report/' + c.[ReportFolder] + '%2f' + c.[Name]
329329
--, [URL] = 'http://' + Host_Name() + '/Reports/manage/catalogitem/editsubscription' + c.[ReportPath] + '?id=' + CAST(s.[SubscriptionID] AS VARCHAR(80))
330330
--, [URL2] = 'http://' + Host_Name() + '/Reports/Pages/Report.aspx?ItemPath=' + c.[ReportPath] + '&SelectedTabId=SubscriptionsTab'
331-
, [ReportCreatedBy] = urc.[SimpleUserName]
332-
, c.[ReportCreationDate]
333-
, [ReportModifiedBy] = urm.[SimpleUserName]
334-
, c.[ReportModifiedDate]
335-
, [SubscriptionOwner] = usc.[SimpleUserName]
336-
, [SubscriptionModifiedBy] = usm.[SimpleUserName]
337-
, [SubscriptionModifiedDate] = s.[ModifiedDate]
338-
, s.[SubscriptionID]
339-
, s.[SubscriptionDescription]
340-
, s.[ExtensionSettings]
341-
, s.[EventType]
342-
, s.[EmailSubject]
343-
, s.[EmailTo]
344-
, s.[EmailCc]
345-
, s.[EmailBcc]
346-
, s.[EmailComment]
347-
, s.[EmailIncludeLink]
348-
, s.[EmailRenderFormat]
349-
, s.[EmailPriority]
350-
, s.[DeliveryExtension]
351-
, s.[SubscriptionLastStatus]
352-
, s.[StatusFail]
353-
, s.[MatchData]
354-
, s.[RunTime]
355-
, s.[LastRunDate]
356-
, s.[LastRunTime]
357-
, s.[MinutesInterval]
358-
, s.[DaysInterval]
359-
, s.[WeeksInterval]
360-
, s.[DaysOfWeek]
361-
, s.[DaysOfMonth]
362-
, s.[Month]
363-
, s.[MonthlyWeek]
364-
, [JobName] = NULL --, s.[JobName]
365-
, s.[ScheduleName]
366-
, s.[ScheduleDays]
367-
, s.[SchDaySun]
368-
, s.[SchDayMon]
369-
, s.[SchDayTue]
370-
, s.[SchDayWed]
371-
, s.[SchDayThr]
372-
, s.[SchDayFri]
373-
, s.[SchDaySat]
374-
, s.[ScheduleStartDate]
375-
, s.[ScheduleEndDate]
376-
, s.[Flags]
377-
, s.[RecurrenceType]
378-
, s.[State]
379-
, [EventStatus] = el.[Status]
380-
, [EventDateTime] = el.[TimeEnd]
381-
FROM
382-
report_catalog AS c
383-
INNER JOIN report_subscription AS s ON s.[Report_OID] = c.[ItemID]
384-
LEFT JOIN
385-
(
386-
SELECT
387-
b.[ReportID]
388-
, b.[Status]
389-
, b.[TimeEnd]
390-
, [LastRunTime] = CAST(CONVERT(CHAR(16), b.[TimeEnd], 113) AS DATETIME)
391-
FROM
392-
dbo.[ExecutionLog] b
393-
INNER JOIN (SELECT [ReportID], MAX([TimeEnd]) AS [TimeEnd] FROM dbo.[ExecutionLog] GROUP BY [ReportID]) a ON b.[ReportID] = a.[ReportID] AND b.[TimeEnd] = a.[TimeEnd]
394-
GROUP BY
395-
b.[ReportID]
396-
, b.[Status]
397-
, b.[TimeEnd]
398-
)AS el ON el.[ReportID] = c.[ItemID]
399-
LEFT JOIN report_users AS urc ON c.[CreatedById] = urc.[UserID]
400-
LEFT JOIN report_users AS urm ON c.[ModifiedById] = urm.[UserID]
401-
LEFT JOIN report_users AS usc ON s.[OwnerID] = usc.[UserID]
402-
LEFT JOIN report_users AS usm ON s.[ModifiedByID] = usm.[UserID]
403-
WHERE
404-
1=1
405-
AND c.[Type] = 2
406-
AND (@all_value IN (@ReportFolder) OR c.[ReportFolder] IN(@ReportFolder))
407-
AND (@all_value IN (@ReportFolder) OR CHARINDEX(@ReportFolder, c.[ReportPath]) > 0)
331+
, [ReportCreatedBy] = urc.[SimpleUserName]
332+
, c.[ReportCreationDate]
333+
, [ReportModifiedBy] = urm.[SimpleUserName]
334+
, c.[ReportModifiedDate]
335+
, [SubscriptionOwner] = usc.[SimpleUserName]
336+
, [SubscriptionModifiedBy] = usm.[SimpleUserName]
337+
, [SubscriptionModifiedDate] = s.[ModifiedDate]
338+
, s.[SubscriptionID]
339+
, s.[SubscriptionDescription]
340+
, s.[ExtensionSettings]
341+
, s.[EventType]
342+
, s.[EmailSubject]
343+
, s.[EmailTo]
344+
, s.[EmailCc]
345+
, s.[EmailBcc]
346+
, s.[EmailComment]
347+
, s.[EmailIncludeLink]
348+
, s.[EmailRenderFormat]
349+
, s.[EmailPriority]
350+
, s.[DeliveryExtension]
351+
, s.[SubscriptionLastStatus]
352+
, s.[StatusFail]
353+
, s.[MatchData]
354+
, s.[RunTime]
355+
, s.[LastRunDate]
356+
, s.[LastRunTime]
357+
, s.[MinutesInterval]
358+
, s.[DaysInterval]
359+
, s.[WeeksInterval]
360+
, s.[DaysOfWeek]
361+
, s.[DaysOfMonth]
362+
, s.[Month]
363+
, s.[MonthlyWeek]
364+
, [JobName] = NULL --, s.[JobName]
365+
, s.[ScheduleName]
366+
, s.[ScheduleDays]
367+
, s.[SchDaySun]
368+
, s.[SchDayMon]
369+
, s.[SchDayTue]
370+
, s.[SchDayWed]
371+
, s.[SchDayThr]
372+
, s.[SchDayFri]
373+
, s.[SchDaySat]
374+
, s.[ScheduleStartDate]
375+
, s.[ScheduleEndDate]
376+
, s.[Flags]
377+
, s.[RecurrenceType]
378+
, s.[State]
379+
, [EventStatus] = el.[Status]
380+
, [EventDateTime] = el.[TimeEnd]
381+
FROM
382+
report_catalog AS c
383+
INNER JOIN report_subscription AS s ON s.[Report_OID] = c.[ItemID]
384+
LEFT JOIN
385+
(
386+
SELECT
387+
b.[ReportID]
388+
, b.[Status]
389+
, b.[TimeEnd]
390+
, [LastRunTime] = CAST(CONVERT(CHAR(16), b.[TimeEnd], 113) AS DATETIME)
391+
FROM
392+
ReportServer.dbo.[ExecutionLog] b
393+
INNER JOIN (SELECT [ReportID], MAX([TimeEnd]) AS [TimeEnd] FROM ReportServer.dbo.[ExecutionLog] GROUP BY [ReportID]) a ON b.[ReportID] = a.[ReportID] AND b.[TimeEnd] = a.[TimeEnd]
394+
GROUP BY
395+
b.[ReportID]
396+
, b.[Status]
397+
, b.[TimeEnd]
398+
)AS el ON el.[ReportID] = c.[ItemID]
399+
LEFT JOIN report_users AS urc ON c.[CreatedById] = urc.[UserID]
400+
LEFT JOIN report_users AS urm ON c.[ModifiedById] = urm.[UserID]
401+
LEFT JOIN report_users AS usc ON s.[OwnerID] = usc.[UserID]
402+
LEFT JOIN report_users AS usm ON s.[ModifiedByID] = usm.[UserID]
403+
WHERE
404+
1=1
405+
AND c.[Type] = 2
406+
AND (@all_value IN (@ReportFolder) OR c.[ReportFolder] IN(@ReportFolder))
407+
AND (@all_value IN (@ReportFolder) OR CHARINDEX(@ReportFolder, c.[ReportPath]) > 0)
408408
AND (@all_value IN(@ReportName) OR c.[Name] IN(@ReportName))
409409
AND (@all_value IN(@EventStatus) OR el.[Status] IN(@EventStatus))
410410
AND (@all_value IN(@Current) OR CASE WHEN s.[ScheduleEndDate] IS NULL THEN 'Current' WHEN s.[ScheduleEndDate] IS NOT NULL THEN 'Non Current' END = @Current)

0 commit comments

Comments
 (0)