>Query 汇总了按货币分组的前 500 个帐户余额,用于从新 SQL 2012 服务器和现有服务器进行比较查询,以验证新 2012 服务器中没有更改。
将超时属性设置为 |set option|command|900| 并且无济于事。
以下是错误的摘录:
System.Data.SqlClient.SqlException (0x80131904(:超时已过期。 操作完成之前经过的超时期限或服务器没有响应。 at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection( at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(( at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj( at System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo( at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj( at System.Data.SqlClient.SqlDataReader.ConsumeMetaData(( 在 System.Data.SqlClient.SqlDataReader.get_MetaData(( at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString( at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async( at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result( at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method( at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method( at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior( at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior( at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior( at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior( at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet( 在DBFIT。DatabaseTest.GetDataTable(Symbol symbols, String query, IDbEnvironment environment, Int32 rsNo( at dbfit.fixture.StoreQuery.DoTable(Parse table( at fitSharp.Fit.Operator.InterpretFlow.DoTable(Tree'1 table, Interpreter activeFixture, Boolean inFlow(
我试图将要检查的行数从 300 减少到 500,这似乎有效,但是大型数据集是突出显示任何差异的理想选择。
我还在考虑将查询更改为其他内容,以将其分解为较小的结果集或创建替代方案
查询如下,如果有人有更好的解决方案来优化查询:
select
TOP 1000 fab.DateKey,be.BK_ActOId,be.PtId,be.PDesc,
be.OId,be.ODesc,be.SubOId,be.SubODesc,
rc.Currency,SUM(CASE WHEN rc.Currency = '_NA' THEN FAB.Balance ELSE 0 END) as bal_OrigCcy
,SUM(CASE WHEN rc.Currency = 'AUD' THEN FAB.Balance ELSE 0 END) as bal_AUD
,SUM(CASE WHEN rc.Currency = 'GBP' THEN FAB.Balance ELSE 0 END) as bal_GBP
,SUM(CASE WHEN rc.Currency = 'SGD' THEN FAB.Balance ELSE 0 END) as bal_SGD
,SUM(CASE WHEN rc.Currency = 'USD' THEN FAB.Balance ELSE 0 END) as bal_USD
from olap.v_FactAccB fab
inner join OLAP.v_DimCur dc on dc.CurrencyKey = fab.BalanceCurrencyKey
inner join olap.v_DimReportingCur rc on rc.CurrencyKey = fab.ReportingCurrencyKey
inner join OLAP.v_DimBusinessEntity be on be.BusinessEntityKey = fab.BusinessEntityKey
and rc.Currency in ('_NA', 'AUD', 'GBP', 'SGD','USD')
and fab.DateKey = 20130912
and fab.PlatformKey = 1
group by fab.DateKey, be.BK_ActOId, be.PId, be.PDesc
,be.OId, be.ODesc, be.SubOId, be.SubODesc, rc.Currency
order by fab.DateKey, be.BK_ActOId, be.PId, be.PDesc, be.OId, be.ODesc, be.SubOId, be.SubODesc, rc.Curr
除了上述之外,有没有人有其他选择
我会重写您的查询以使用PIVOT
而不是重复的SUM(CASE... )
例如:
select * from yourtable
pivot (SUM(balance) for currency in (_NA,AUD,GBP,SGD,USD)) p