Thank you for all of that Brian, that is helping me start to understand what is going on here. Here is my best explanation:
There is a sub-query with filter criteria
JobOper.JobNum FOR XML PATH(‘’)
So based on your explanation, this is intended to generate a string of concatenated values with a comma in-between, but with all of that XML stuff in there too.
Then the only displayed value for Subquery2 is a calculated field of:
(case when sum(convert(int,JobMtl.IssuedComplete)) = count(JobMtl.MtlSeq) then 1 else 0 end)
Then in the BAQ’s primary query, there is a calculated field named ALLIssued
whose expression is:
substring({subquery2},23,1)
My best guess of that calculated field is that it’s pulling out a specific value (the 23rd character) because the rest of it is the XML mumbo-jumbo?
So the first thing I did was just remove the sub-query filter criteria (the stuff with the FOR XML) and change the calculated field to be just {subquery2}. This returns 4200 rows so the query no longer errors out, but I am going to assume it is returning too many results because filter criteria that was previously there is now gone.
So my next step was to try replacing the Subquery2 filter criteria
JobOper.JobNum FOR XML PATH(‘’)
with
STRING_AGG(JobOper.JobNum,",")
or
STRING_AGG(JobOper.JobNum,',')
but both of those error out with the error below. Any pointers for next steps? This is an interesting problem.
Ice.Common.EpicorServerException: Column 'Erp.JobOper.DueDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. ---> System.Data.SqlClient.SqlException: Column 'Erp.JobOper.DueDate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
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 Ice.Blaq.Execution.QueryExecutor.ExecuteAndFillDataSetInternal(IDbConnection dbconn, QueryInfo queryInfo, DataSet resultDataset, Action`2 perfLogger) in C:\_releases\ICE\ICE3.2.700.34\Source\Server\Internal\Lib\Ice.Lib.Blaq\Execution\QueryExecutor.cs:line 118
at Ice.Blaq.Execution.QueryExecutor.<>c__DisplayClass3_0.<ExecuteAndFillDataSet>b__0(IDbConnection dbconn) in C:\_releases\ICE\ICE3.2.700.34\Source\Server\Internal\Lib\Ice.Lib.Blaq\Execution\QueryExecutor.cs:line 37
at Ice.Blaq.Execution.QueryExecutionHelper.DoJobWithObject[TObj](Func`2 theJob) in C:\_releases\ICE\ICE3.2.700.34\Source\Server\Internal\Lib\Ice.Lib.Blaq\Execution\QueryExecutionHelper.cs:line 195
--- End of inner exception stack trace ---