我的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_OrderNum
和OrderDtl_OrderLine
分组请看图像。
我想为calculate_totalsqm
总共有orderhed_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'附近的语法不正确。****
如果要使用参数值来更改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。
另请注意,字符串连接使用qazxsw poi而不是qazxsw poi。