【问题标题】:SSRS returned data type not valid for the aggregate functionSSRS 返回的数据类型对于聚合函数无效
【发布时间】:2017-07-06 01:52:08
【问题描述】:

执行查询时,我正在制作 SSRS

SELECT Brand.[KeyOffer],
   COALESCE(SUM([Key Offer].Revenue),0) as Revenue
FROM [Brand Key Offer] Brand
LEFT JOIN [Key Offer] ON Brand.Keyoffer = [Key Offer].[Key Offer] AND [Key Offer].[Date] = '7/05/2017'
WHERE Brand.[Brand] = 'SMART'
GROUP BY [Brand].[KeyOffer]
ORDER BY [Revenue] DESC

但是当我预览报告时,我收到了这条警告消息。

Warning     [rsAggregateOfInvalidExpressionDataType] The Value expression for the textrun ‘Textbox21.Paragraphs[0].TextRuns[0]’ uses an aggregate function with an expression that returned a data type not valid for the aggregate function.       c:\users\t-aordiz\documents\visual studio 2015\Projects\TelemarketingRS\TelemarketingRS\Telemarketing Revenue.rdl   0   

我去过很多主题,但似乎找不到解决这个问题的方法。

【问题讨论】:

  • 我不确定这与您的查询有关。您的查询是否在 SSMS 中运行?我认为这可能与 textbox21 中的某些内容有关。那个文本框有表达式吗?

标签: reporting-services


【解决方案1】:

当我尝试将输出的数据类型从 datetime 更改为 varchar 时,我也遇到了同样的情况。

尝试删除文件 YourReportFile.rdl.data 并再次预览。它在 VS2015 中对我有用。

【讨论】:

  • 谢谢 - 删除 *.rdl.data 文件为我解决了这个问题。
【解决方案2】:

看起来错误是由对SUM() 的调用引起的,可能是因为您为其提供了非数字类型。要对此进行测试,您可以尝试将 [Key Offer].Revenue 转换为十进制:

SELECT
    Brand.[KeyOffer],
    COALESCE(SUM(CAST([Key Offer].Revenue AS DECIMAL(10, 2))),0) AS Revenue
FROM [Brand Key Offer] Brand
...

【讨论】:

    【解决方案3】:

    您可以在表达式中使用转换为合适的类型,如下所示

    = CDec(Fields!Revenue.value)
    

    还可以尝试以下 SQL 替代方法

    COALESCE(SUM([Key Offer].Revenue),0.00) 
    

    CAST(COALESCE(SUM([Key Offer].Revenue),0) AS DECIMAL(10, 2))
    

    (和蒂姆建议的有点不同)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 2018-11-19
      • 2018-01-06
      • 2019-02-11
      • 1970-01-01
      相关资源
      最近更新 更多