【问题标题】:Group total in ssrsssrs 中的组总数
【发布时间】:2019-02-23 16:21:24
【问题描述】:

我的 SQL 查询返回:

orderhed_pino_c OrderHed_OrderNum   OrderDtl_OrderLine  calculated_totalsqm
19.0503 50291   1   1.6359
19.0503 50291   1   1.6359
19.0503 50291   2   1.59244
19.0503 50291   2   1.59244
19.0503 50292   1   28.0476
19.0503 50290   1   3.2718
19.0503 50288   1   7.418808
19.0503 50288   1   7.418808
19.0503 50288   1   7.418808
19.0503 50290   3   1
19.0503 50288   1   7.418808
19.0503 50288   1   7.418808
19.0503 50288   1   7.418808
19.0503 50290   4   38.868
19.0503 50288   1   7.418808
19.0503 50288   1   7.418808
19.0503 50288   1   7.418808

在 SSRS 中,我按 OrderHed_OrderNumOrderDtl_OrderLine 分组 请看图片。

我想要calculate_totalsqmorderhed_ordernum 的总数。

但我得到了所有行的总数。

对于orderhed_ordernum = 50291,我有两个orderdtl_orderline 1 和2,所以总数应该是1.6359 + 1.59244 = 3.22834

但 SSRS 显示为 6.45。

我的数据集查询为:

SELECT Sum(t1)
FROM (
  SELECT [orderhed_ordernum] AS T2
    , Avg([calculated_totalsqm]) AS T1
    , [orderdtl_orderline] AS T3
  FROM dbo.[baqreportresult_" + parameters!tableguid.value + "]
  GROUP BY [orderhed_ordernum], [orderdtl_orderline]
) BB
GROUP  BY t2  

但我收到错误:

程序 Ice.Services.Lib.RunTask 引发意外异常,并显示以下消息:RunTask: System.Web.Services.Protocols.SoapException: 在报告处理期间发生错误。 ---> Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException:报告处理过程中发生错误。 ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException:数据集“TotalSQM”的查询执行失败。 ---> System.Data.SqlClient.SqlException:关键字'By'附近的语法不正确。****

【问题讨论】:

  • 请格式化您的问题,使其可读meta.stackexchange.com/questions/22186/…
  • 在查询中你引用的参数不是@tableguid吗?
  • 但我不认为你可以使用参数创建动态 SQL
  • 请帮忙,有什么好的方法可以做到这一点?
  • 我不知道 - 从你的问题中不清楚你想要达到什么目的......你有多少不同的桌子?

标签: reporting-services ssrs-2008


【解决方案1】:

如果您想使用参数值来更改 Sql 语句的文本(即提供数据库、表或字段名称),则将整个 Sql 语句转换为表达式。右键单击数据集,单击属性,然后单击 Sql 语句旁边的fx 按钮进行编辑并将其转换为字符串表达式。输入以下内容:

="SELECT Sum(t1) "
&"FROM ( "
&"  SELECT [orderhed_ordernum] AS T2 "
&"    , Avg([calculated_totalsqm]) AS T1 "
&"    , [orderdtl_orderline] AS T3 "
&"  FROM dbo.[baqreportresult_" & Parameters!tableguid.value & "] "
&"  GROUP BY [orderhed_ordernum], [orderdtl_orderline] "
&") BB "
&"GROUP BY t2 "

所以这只是将整个Sql封装在引号中,将其变成字符串表达式,并将参数值插入到Sql语句中,以便在运行时计算出正确的表名。 Sql 语句是在运行时从字符串表达式构建的,从 tableguid 参数创建所需的表名,然后针对数据库执行该表名。

注意每一行末尾的空格,因为这将导致一行 Sql。

还要注意字符串连接使用& 而不是+

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多