2017-07-06 108 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建議有點不同)