2017-07-06 109 views
1

我想提出一个SSRS,执行查询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 

的Ive到很多话题,但不能似乎找到一个方法来解决这个问题。

+0

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

回答

3

我试图将输出的数据类型从datetime更改为varchar时,也发生了同样的情况。

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

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 
... 
0

您可以使用转换你的表达了恰当类型像下面

= CDec(Fields!Revenue.value) 

也可以尝试下面的SQL替代

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

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

(与Tim建议有点不同)