【问题标题】:SSRS Report Query Not Working, but does when hardcoded parametersSSRS 报告查询不起作用,但在硬编码参数时起作用
【发布时间】:2015-07-24 18:32:57
【问题描述】:

我有一个包含 3 个参数的 SSRS 报告:

@start (datetime)
@end (datetime)
@plantid (string from an external query)

当我定期运行报告时,它会超时。当我在设计器查询生成器中运行它时,它会超时。但是,当我将参数硬编码到查询生成器中时,它可以工作。 整个事情在 Management Studio 中运行良好

为什么当我在查询设计器中提供查询中的参数时,它会运行,但是当我通过报表填写参数时它却没有? 这就是我在设计器查询构建器中添加的内容,以使其快速运行以进行测试。

Declare @start varchar(20),
        @end varchar(20),
        @plantid varchar(10)

        set @start='07/13/2015'
        set @end = '07/17/2015'
        set @plantid = 'mnp'

Select Division as 'Division', SUM(SALESQTY) as 'salesQTY',rtrim(Ltrim(salesline.itemgroupid)) as 'itemGroup'
FROM MiscReportTables.dbo.PlantDivisions 
inner join prodtable on prodtable.dimension2_ = MiscReportTables.dbo.PlantDivisions.Division
inner join SalesLine on SalesLine.InventrefId = ProdTable.ProdiD
WHERE PlantID IN (@plantid)
and SCHEDDATE between @start and @end
Group By Division,salesLine.itemgroupid

编辑: 我把它做成了一个存储过程并正在运行它,即使在管理工作室中也需要很长时间(60 多分钟)。我在其中添加了option (recompile) 以停止参数嗅探。

【问题讨论】:

  • 当你使用 profiler 抓取需要 15 分钟的 SSRS 发送的命令,然后直接在 SSMS 中执行该命令时会发生什么?
  • 它永远不会在 SSRS 中运行。当我在 SSMS 中执行存储过程时,到目前为止已经花费了 2 个小时,而当我使用查询本身的参数时,它需要 20 秒
  • 您的“@PlantID”参数是否需要是多值列表?您的“IN”语句最有可能成为性能杀手。
  • 好的,您最初的问题是“整个事情在 Management Studio 中运行良好”,这是一种误导。执行计划作为主要资源用户显示什么?

标签: sql-server reporting-services ssrs-2008-r2


【解决方案1】:

您是否尝试将参数分配给查询中的不同变量?

我忘记了理论是什么,但在类似的情况下这对我有用。

    Declare @start1 varchar(20),
    @end1 varchar(20),
    @plantid1 varchar(10)

    set @start1 =@start 
    set @end1 = @end 
    set @plantid1 = @plantid

Select Division as 'Division', SUM(SALESQTY) as 'salesQTY',rtrim(Ltrim(salesline.itemgroupid)) as 'itemGroup'
FROM MiscReportTables.dbo.PlantDivisions 
inner join prodtable on prodtable.dimension2_ = MiscReportTables.dbo.PlantDivisions.Division
inner join SalesLine on SalesLine.InventrefId = ProdTable.ProdiD
WHERE PlantID IN (@plantid)
and SCHEDDATE between @start and @end
Group By Division,salesLine.itemgroupid

要尝试的另一件事(如果有的话)是部署到报表服务器并从那里运行它。有些报表在 Visual Studio 中需要很长时间,但在 RS 中运行速度很快。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,使用了一种解决方法,即创建单独的参数,但使用附加参数对于可用性来说是不可行的。所以我然后将参数更改为具有使用传入日期中的值的默认值,这有效! (只需要隐藏第二组参数..)

    【讨论】:

      猜你喜欢
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      • 2017-11-10
      相关资源
      最近更新 更多