SSRS返回的数据类型对聚合函数无效

时间:2017-07-06 01:52:09

标签: reporting-services

我在执行查询时正在制作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

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

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   

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

3 个答案:

答案 0 :(得分:9)

当我尝试将输出的数据类型从datetime更改为varchar时,同样的情况发生在我身上。

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

答案 1 :(得分:0)

看起来错误是由对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
...

答案 2 :(得分:0)

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

= CDec(Fields!Revenue.value)

还尝试以下SQL替代方案

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

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

(这与蒂姆建议的有点不同)