SQL Server 报告服务查询

Posted

技术标签:

【中文标题】SQL Server 报告服务查询【英文标题】:SQL Server Reporting Services Query 【发布时间】:2018-01-11 14:37:05 【问题描述】:

我想要一份关于有多少报告成功、多少失败作为计数的报告,并添加了报告名称、提交报告的用户、失败原因、报告路径、订阅、计划和还可以查看历史数据以显示趋势。

我可以使用哪些表格来获取制作报告所需的数据?

我找到了一个查询,它可以为我提供执行此报告所需的部分信息,但它已过时,因为它包含的表不再在 sql-server 2012 的报告服务器数据库中找到

任何帮助或指导将不胜感激。

[链接到过时的查询]https://social.msdn.microsoft.com/Forums/sqlserver/en-US/c6b35fff-2a46-46ce-bc1e-c166a4d65c2d/s-s-rs-notification-of-success-or-failure-of-report-generation?forum=sqlreportingservices

[链接到我之前关于这个主题的问题]Incompatible SQL Server Reporting Services Query

【问题讨论】:

【参考方案1】:

这是我用来搜索 Reporting Services 执行日志的查询。此外,还有一些关于GitHub的示例报告

DECLARE @all_value AS VARCHAR(10)
DECLARE @LogStatus AS VARCHAR(50)
DECLARE @ReportFolder AS VARCHAR(450)
DECLARE @ReportName AS VARCHAR(450)
DECLARE @UserName AS VARCHAR(260)
DECLARE @StartDate AS DATETIME
DECLARE @EndDate AS DATETIME

SET @all_value = '<ALL>'
SET @LogStatus = '<ALL>' --filter your execution log status here
SET @ReportFolder = '...A Report Folder Name...'
SET @ReportName = '<ALL>' 
SET @UserName = '<ALL>'
SET @StartDate = NULL
SET @EndDate = NULL



;WITH
report_users 
AS
(
    SELECT UserID, UserName, SimpleUserName = UPPER(RIGHT(UserName, (LEN(UserName)-CHARINDEX('\',UserName)))) FROM dbo.Users
)
,
report_catalog
AS
(
    SELECT    
        rpt.ItemID
      , rpt.CreatedById
      , rpt.ModifiedById
      , rpt.[Type]
      , rpt.[Name] 
      , ReportName = rpt.[Name] 
      , rpt.[Description]
      , rpt.Parameter
      , CreationDate = CONVERT(DATETIME, CONVERT(VARCHAR(11), rpt.CreationDate, 13))
      , ModifiedDate = CONVERT(DATETIME, CONVERT(VARCHAR(11), rpt.ModifiedDate, 13))
      , ReportFolder = SUBSTRING(rpt.[Path], 2, Len(rpt.[Path])-Len(rpt.[Name])-2) 
      , rpt.[Path]
      , URL_ReportFolder = 'http://' + Host_Name() + '/Reports/Pages/Report.aspx?ItemPath=%2f'  + SUBSTRING(rpt.[Path], 2, Len(rpt.[Path])-Len(rpt.[Name])-2)  + '&ViewMode=List'
      , 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]
      , ReportDefinition = CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), rpt.Content))  
      , HostName = Host_Name()
    FROM 
      dbo.Catalog AS rpt
    WHERE 
      1=1
      AND rpt.[Type] = 2
)
    SELECT 
      ReportPath = rpt.[Path]
    , rpt.ReportFolder
    , ReportName = rpt.[Name]
    , rpt.URL_ReportFolder
    , rpt.URL_Report 
    , URL_Report_Filtered = rpt.URL_Report + '&rs:Command=Render&' + CONVERT(VARCHAR(2000), el.[Parameters])
    , UserName = usr.SimpleUserName
    , el.[Status]
    , el.TimeStart
    , el.[RowCount]
    , el.ByteCount
    , el.[Format]
    , el.[Parameters]
    , TotalSeconds = CONVERT(CHAR(8),DATEADD(ms,(el.TimeDataRetrieval + el.TimeProcessing + el.TimeRendering),0),108)
    , TimeDataRetrieval = CONVERT(CHAR(8),DATEADD(ms,el.TimeDataRetrieval,0),108) 
    , TimeProcessing = CONVERT(CHAR(8),DATEADD(ms,el.TimeProcessing,0),108)  
    , TimeRendering = CONVERT(CHAR(8),DATEADD(ms,el.TimeRendering,0),108) 
    , OrderbyDate = CAST(TimeStart AS DATETIME) 
FROM 
    report_catalog AS rpt 
    LEFT JOIN dbo.ExecutionLog AS el ON el.ReportID = rpt.ItemID
    LEFT JOIN report_users AS usr ON el.UserName = usr.UserName
WHERE 
    1=1
    AND (@all_value IN(@LogStatus) OR el.[Status] IN(@LogStatus))
    AND (@all_value IN(@ReportFolder) OR rpt.ReportFolder IN(@ReportFolder))
    AND (@all_value IN(@ReportName) OR rpt.ReportName IN(@ReportName))
    AND (@all_value IN(@UserName) OR usr.SimpleUserName IN(@UserName))
    AND (@StartDate IS NULL OR CONVERT(DATETIME, CONVERT(VARCHAR(11),el.TimeStart,13)) >= @StartDate)
    AND (@EndDate IS NULL OR CONVERT(DATETIME, CONVERT(VARCHAR(11),el.TimeStart,13)) <= @EndDate)

【讨论】:

【参考方案2】:

这应该有帮助

https://docs.microsoft.com/en-us/sql/reporting-services/report-server/report-server-executionlog-and-the-executionlog3-view

Use ReportServer  
select * from ExecutionLog3 order by TimeStart DESC 


Use ReportServer  
select * from ExecutionLog2 order by TimeStart DESC 

【讨论】:

以上是关于SQL Server 报告服务查询的主要内容,如果未能解决你的问题,请参考以下文章

使用 SQL Server Express 的报告服务

.rdl 报告(sql server 报告服务)的文本开头未显示换行符

SQL Server 2008 查询正向现金流报告

如何从 SQL Server Express 中的动态查询创建 RDLC 报告

如何使用表单身份验证部署 SQL Server 报告服务?

通过 url 将参数传递给 sql server 报告服务