为什么聚合包含转换函数的字段会导致转换错误?

时间:2018-12-20 10:44:54

标签: reporting-services reportbuilder3.0

我有一个奇怪的问题。

上下文: 我正在SSRS的Report Builder 3.0中编写报告。在某些情况下,我被迫使用预定义的数据模型,我无权直接访问数据库,因此无法在SQL或类似的语言中直接使用CAST。我必须坚持使用报表生成器的查询设计器中的功能。

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

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

已经过滤掉了非“数字”行,我需要将其余的“数字”结果转换为数字数据类型,这是通过Report Builder查询设计器中的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()函数已经执行了该转换,并且效果很好。我可以只用INT(Result)运行查询,它返回的数据很好。那么,考虑到转换步骤显然工作正常,为什么在我尝试对该转换后的字段执行聚合时SSRS会抛出错误?

1 个答案:

答案 0 :(得分:0)

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

佐伊