Could not complete cursor operation because the table schema changed after the cursor was declared

Sometimes during batch job running, the below error will be thrown.

ERROR MESSAGE IN BATCHJOB:

SQL error description: [Microsoft][SQL Native Client][SQL Server]Could not complete cursor operation because the table schema changed after the cursor was declared.

Can you show us the piece of code in question?

void queryBuild()
{
QueryBuildDataSource qbds; QueryBuildRange qbrPaymStatus, qbrPaymType;
;
query = new Query(querystr(PaymentTableQuery));
qbds = query.dataSourceTable(tablenum(PaymentTable));

qbrCardNum = qbds.addRange(fieldNum(PaymentTable, CardNumber)); qbrCardNum.value(SysQuery::valueNotEmptyString()); qbrPaymType = qbds.addRange(fieldNum(PaymentTable, PaymType)); qbrPaymType.value(strfmt("%1,%2",queryValue(CustSalesPaymType::CardRefund),queryvalue(CustSalesPaymType::PaypalRefund)));
qbrPaymStatus = qbds.addRange(fieldNum(PaymentTable, PaymStatus)); qbrPaymStatus.value(queryvalue(PaymStatus::PendingSettlement));
queryRun = new SysQueryRun(query); }

The error message suggests that something updates the data while the query result it processing. If it’s the case, the bug is after the code you’ve shown, because that’s just the definition of the query, not the code doing something with it.
By the please use Insert > Insert code in the rich formatting view to insert code snippets. It’s almost unreadable without it.