Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reporting services 已传递SSRS报告参数_Reporting Services_Ssrs 2008_Ssrs 2008 R2_Ssrs 2012 - Fatal编程技术网

Reporting services 已传递SSRS报告参数

Reporting services 已传递SSRS报告参数,reporting-services,ssrs-2008,ssrs-2008-r2,ssrs-2012,Reporting Services,Ssrs 2008,Ssrs 2008 R2,Ssrs 2012,我目前正在构建一些日志记录和分析工具,以跟踪我们的SQL环境。我们目前正在使用SQL Server 2014 我想做的是检查白天传递给我们报告的所有参数。所有报表当前都使用存储过程,因此在“我的表”或基于表的select语句中,每次运行报表时都会输出存储过程的参数 最后,我希望能够获取输出的语句并在SSMS中运行它,而不必使用报告。我一直在查看ExchangionLogStorage表和ExecutionLog视图,尽管它包含了我需要的大部分信息,但这些参数并不处于易于使用的状态 有人做过类似于

我目前正在构建一些日志记录和分析工具,以跟踪我们的SQL环境。我们目前正在使用SQL Server 2014

我想做的是检查白天传递给我们报告的所有参数。所有报表当前都使用存储过程,因此在“我的表”或基于表的select语句中,每次运行报表时都会输出存储过程的参数

最后,我希望能够获取输出的语句并在SSMS中运行它,而不必使用报告。我一直在查看ExchangionLogStorage表和ExecutionLog视图,尽管它包含了我需要的大部分信息,但这些参数并不处于易于使用的状态


有人做过类似于我所描述的事情吗?

您需要在原始SP中添加日志部分,例如:

Alter procedure a
(@parameter)
As
Begin
..
..
Insert into loggingTable(col)
Values(@parameter)
..
..
End 

然后直接查询该日志表以获取所用参数的历史记录

围绕该主题的谷歌搜索很快就会找到以下内容,这些内容已经被OP确定为有用的,如下所示(该查询本身实际上是由LONG下面的答案链接的工作的扩展)

不过,这两种方法实际上只为我们提供了一个起点,因为它们(各种)依赖于我们事先知道报告名称和参数名称。虽然我们可以快速地对Ken Bowman的工作进行一些更改,使其针对所有报告的所有执行运行,但我们仍然存在查询硬编码参数名称的问题

执行报告所需的参数存储在“参数”列的目录表中。尽管列具有数据类型ntext,但它实际上存储的是XML字符串。这意味着我们可以使用查询来获取参数名称

with
CatalogData as (
    select ItemID, [Path], [Name], cast(Parameter as xml) 'ParameterXml'
    from Catalog
    where [Type] = 2),
ReportParameters as (
    select ItemID, [Path], [Name], ParameterXml, p.value('Name[1]', 'nvarchar(256)') 'ParameterName'
    from CatalogData
    cross apply ParameterXml.nodes('/Parameters/Parameter') as Parameters(p))
select *
from ReportParameters;
执行此查询将列出服务器上的所有报告及其参数。现在我们只需要将此与Ken Bowman的查询结合起来。我采用了CTE方法

with
CatalogData as (
    select ItemID, [Path], [Name], cast(Parameter as xml) 'ParameterXml'
    from Catalog
    where [Type] = 2),
ReportParameters as (
    select ItemID, [Path], [Name], p.value('Name[1]', 'nvarchar(256)') 'ParameterName'
    from CatalogData
    cross apply ParameterXml.nodes('/Parameters/Parameter') as Parameters(p))
select
    els.TimeEnd
    , c.[Name]
    , rp.ParameterName
    , iif(
        charindex(
            '&' + rp.ParameterName + '=', ParametersString) = 0
            , rp.ParameterName, substring(ParametersString
            , StartIndex, charindex('&', ParametersString, StartIndex) - StartIndex
    )) 'ParameterValue'
from (
    select
        ReportID
        , TimeEnd
        , rp.ParameterName
        , '&' + convert(varchar(max), Parameters) + '&' 'ParametersString'
        , charindex(
            '&' + rp.ParameterName + '=',
            '&' + convert(varchar(max), Parameters) + '&'
        ) + len('&' + rp.ParameterName + '=') 'StartIndex'
    from
    ExecutionLogStorage
    inner join ReportParameters rp on rp.ItemID = ReportID) AS els
inner join [Catalog] c on c.ItemID = els.ReportID
inner join ReportParameters rp on rp.ItemID = c.ItemID and rp.ParameterName = els.ParameterName;

请注意,参数值作为URL的一部分传递给报表,因此仍然需要去掉文本空间编码等。此外,这(还…)不适用于多值参数。

这假设存储过程仅由report executionHi Long调用,感谢您的回复,非常感谢,当所有参数已存储在ExecutionLogStorage表中时,再次重新记录所有参数似乎很麻烦,即使它们不是最容易使用的格式。我还有许多存储过程需要添加此示例代码,这将花费大量时间。希望这将对您的情况有所帮助:嗨,Paul,谢谢您的回复,我在旅行中确实遇到了此代码,并尝试运行它,但没有得到什么回报,我删除了where子句以获取ExecutionLogStorage中的所有内容,但继续返回一个名为ParValue的列,其记录值为ParameterName。还有什么我需要做的,使这项工作,任何其他的帮助将是伟大的!所提供的查询用于单个报表的最近执行。要获取所有报告/执行,请删除“SELECT TOP 1 ParValue FROM”()以及“WHERE c.Name…”后面的所有内容子句。您可能也会删除UserName where子句。当然,我们一直在使用每个报表中的参数名称来获取它。这些名称可以找到目录表的参数列。尽管ntext实际上是XML,因此可以查询。这是一个安静的早晨(员工/学生下周才回来!)兴趣激发了我,所以我更进一步。请看我修改后的答案以获得解决方案Hi Paul,谢谢你花时间帮助我,我也朝着与你相同的方向走了,但你的代码看起来更整洁了。这确实是我想要的,但正如你所说,对多值参数b不起作用ut是一个伟大的出发点,它将为我指明正确的方向,如果你想要一份完成的代码的副本,请通过私人消息告诉我。
with
CatalogData as (
    select ItemID, [Path], [Name], cast(Parameter as xml) 'ParameterXml'
    from Catalog
    where [Type] = 2),
ReportParameters as (
    select ItemID, [Path], [Name], p.value('Name[1]', 'nvarchar(256)') 'ParameterName'
    from CatalogData
    cross apply ParameterXml.nodes('/Parameters/Parameter') as Parameters(p))
select
    els.TimeEnd
    , c.[Name]
    , rp.ParameterName
    , iif(
        charindex(
            '&' + rp.ParameterName + '=', ParametersString) = 0
            , rp.ParameterName, substring(ParametersString
            , StartIndex, charindex('&', ParametersString, StartIndex) - StartIndex
    )) 'ParameterValue'
from (
    select
        ReportID
        , TimeEnd
        , rp.ParameterName
        , '&' + convert(varchar(max), Parameters) + '&' 'ParametersString'
        , charindex(
            '&' + rp.ParameterName + '=',
            '&' + convert(varchar(max), Parameters) + '&'
        ) + len('&' + rp.ParameterName + '=') 'StartIndex'
    from
    ExecutionLogStorage
    inner join ReportParameters rp on rp.ItemID = ReportID) AS els
inner join [Catalog] c on c.ItemID = els.ReportID
inner join ReportParameters rp on rp.ItemID = c.ItemID and rp.ParameterName = els.ParameterName;