首页 > 解决方案 > 为什么聚合包含转换函数的字段会导致转换错误?

问题描述

我有一个奇怪的问题。

上下文: 我正在 SSRS 的 Report Builder 3.0 中编写报告。环境迫使我使用预定义的数据模型,我没有对数据库的直接查询访问权限,因此不能直接CAST在 SQL 或类似的东西中使用。我必须坚持报表生成器的查询设计器中的功能。

问题: 我有一个数据表,每个学生每个科目每个“结果类型”都有一行,以及一列 nvarchar 格式的相关结果,其中一些值是字母的组合,一些是数字的组合,对于例子:

| Student Number | Subject | Result Type | Result |
|----------------|---------|-------------|--------|
|  0123456       | Maths   |   ELRCC     |  XEA   |
|  0123456       | Maths   |   ELMSS     |  110   |

已经过滤掉了非“数字”行,我需要将剩余的“数字”结果转换为数字数据类型,这是通过INT()报表生成器的查询设计器中的函数来完成的。这工作正常。

然后,我在查询设计器中对学生编号上的数据进行分组并将其包装INT()起来AVERAGE()以获取AVERAGE(INT(Result))- 当我尝试使用包含为字段的公式运行查询时,报表服务器会引发以下错误:

===================================

An error occurred while executing the query.
An error occurred when the query ran. Refer to the inner exception for details. (Microsoft SQL Server Report Builder)

===================================

An error occurred when the query ran. Refer to the inner exception for details. (mscorlib)

------------------------------
Program Location:


Server stack trace: 
   at Microsoft.ReportingServices.RsClient.RsCommand.ExecuteRsDataReader()
   at Microsoft.ReportingServices.RsClient.RsCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at Microsoft.ReportingServices.RsClient.RsCommand.ExecuteReader()
   at Microsoft.ReportingServices.DataExtensions.ReportServerDataProvider.RSDPCommand.ExecuteReader(CommandBehavior behavior)
   at Microsoft.ReportingServices.QueryDesigners.MultiThreadedQueryResultsHelper.AsyncExecuteReader(IDbCommand command, CommandBehavior behaviour)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
   at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
   at Microsoft.ReportingServices.QueryDesigners.MultiThreadedQueryResultsHelper.ExecuteReaderHandler.EndInvoke(IAsyncResult result)
   at Microsoft.ReportingServices.QueryDesigners.MultiThreadedQueryResultsHelper.<>c__DisplayClass1.<ExecuteActiveQueryCallback>b__0()
   at Microsoft.ReportingServices.QueryDesigners.QueryResultsGrid.EndExecuteReaderInUiThread(GetDataReaderHandler getDataReaderCallback)

===================================

The remote server returned an error: (500) Internal Server Error.
<detail><ErrorCode xmlns="http://www.microsoft.com/sql/reportingservices">rsSemanticQueryEngineError</ErrorCode><HttpStatus xmlns="http://www.microsoft.com/sql/reportingservices">400</HttpStatus><Message xmlns="http://www.microsoft.com/sql/reportingservices">Semantic query execution failed. Error converting data type nvarchar to float.</Message><HelpLink xmlns="http://www.microsoft.com/sql/reportingservices">http://go.microsoft.com/fwlink/?LinkId=20476&amp;EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&amp;EvtID=rsSemanticQueryEngineError&amp;ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&amp;ProdVer=11.0.5058.0</HelpLink><ProductName xmlns="http://www.microsoft.com/sql/reportingservices">Microsoft SQL Server Reporting Services</ProductName><ProductVersion xmlns="http://www.microsoft.com/sql/reportingservices">11.0.5058.0</ProductVersion><ProductLocaleId xmlns="http://www.microsoft.com/sql/reportingservices">127</ProductLocaleId><OperatingSystem xmlns="http://www.microsoft.com/sql/reportingservices">OsIndependent</OperatingSystem><CountryLocaleId xmlns="http://www.microsoft.com/sql/reportingservices">1033</CountryLocaleId><MoreInformation xmlns="http://www.microsoft.com/sql/reportingservices"><Source>Microsoft.ReportingServices.SemanticQueryEngine</Source><Message msrs:ErrorCode="rsSemanticQueryEngineError" msrs:HelpLink="http://go.microsoft.com/fwlink/?LinkId=20476&amp;EvtSrc=Microsoft.ReportingServices.Diagnostics.Utilities.ErrorStrings&amp;EvtID=rsSemanticQueryEngineError&amp;ProdName=Microsoft%20SQL%20Server%20Reporting%20Services&amp;ProdVer=11.0.5058.0" xmlns:msrs="http://www.microsoft.com/sql/reportingservices">Semantic query execution failed. Error converting data type nvarchar to float.</Message></MoreInformation><Warnings xmlns="http://www.microsoft.com/sql/reportingservices" /></detail>

===================================

The remote server returned an error: (500) Internal Server Error. (System)

------------------------------
Program Location:

   at System.Net.HttpWebRequest.GetResponse()
   at Microsoft.ReportingServices.RsClient.RsCommand.ExecuteRsDataReader()

最相关的行是:

Semantic query execution failed. Error converting data type nvarchar to bigint.

我不明白为什么我会收到这个错误。该INT()函数已经执行了该转换,并且做得非常好;我可以用 just 运行查询,INT(Result)它会很好地返回数据。那么,鉴于转换步骤显然工作正常,为什么当我尝试对转换后的字段执行聚合时 SSRS 会抛出错误?

标签: reporting-servicesreportbuilder3.0

解决方案


我在我的环境中对此进行了测试,它会很好地工作(=Avg(int(Fields!result.Value)))。我认为这可能不是表达问题。这可能是服务器或工具问题。此外,您还可以参考此修复 以获取详细信息。

佐伊


推荐阅读