Доброго времени суток!
У меня очередной вопрос про Query. Как можно программно создать запрос, который реализовал бы следующий код на X++ :
PHP код:
// . . .
LedgerBalancesDimTrans lb,lbBuf;
// . . .
while select lb
group by dimension
where (
(lb.AccountNum == LedgerDistribByAlg.OffsetAccountNum) ||
(lb.AccountNum == LedgerDistribByAlg.BaseAccountNum)
)
&&
( lb.TransDate <= dateEndMth(ledgerJournalDistribTable.Period))
notexists join lbbuf
where (
(lbbuf.AccountNum == LedgerDistribByAlg.OffsetAccountNum) ||
(lbbuf.AccountNum == LedgerDistribByAlg.BaseAccountNum)
)
&&
( lbbuf.TransDate <= dateEndMth(ledgerJournalDistribTable.Period)) &&
(
(lbbuf.Dimension[_dimensionNumber] !=lb.Dimension[_dimensionNumber] )
)
&&
(lbbuf.Dimension[_dimensionNumber] ==lb.Dimension[_dimensionNumber]
|| lB.Dimension[_dimensionNumber]=='')
{
// . . .
}
// . . .
Я дулаю следующее:
PHP код:
// . . .
q = new Query();
fieldName =strfmt("dimension[%1]", _dimensionNumber)
fieldId = fieldName2Id(tableNum(LedgerBalancesDimTrans), fieldName);
qbds_lb = q.addDataSource(tableNum(LedgerBalancesDimTrans), 'A');
qbds_lb.orderMode(OrderMode::GroupBy);
qbds_lb.addSortField(fieldId);
qbr = qbds_lb.addRange(fieldNum(LedgerBalancesDimTrans, TransDate));
qbr.value(SysQuery::range(DateNull(), dateEndMth(ledgerJournalDistribTable.Period)));
if (LedgerDistribByAlg.OffsetAccountNum)
{
qbr = qbds_lb.addRange(fieldNum(LedgerBalancesDimTrans, AccountNum));
qbr.value(SysQuery::value(LedgerDistribByAlg.OffsetAccountNum));
}
if (LedgerDistribByAlg.BaseAccountNum)
{
qbr = qbds_lb.addRange(fieldNum(LedgerBalancesDimTrans, AccountNum));
qbr.value(SysQuery::value(LedgerDistribByAlg.BaseAccountNum));
}
qbds_lbbuf = qbds_lb.addDataSource(tableNum(LedgerBalancesDimTrans), 'B');
qbds_lbbuf.relations( false );
qbr = qbds_lbbuf.addRange(fieldNum(LedgerBalancesDimTrans, TransDate));
qbr.value(SysQuery::range(DateNull(), dateEndMth(ledgerJournalDistribTable.Period)));
if (LedgerDistribByAlg.OffsetAccountNum)
{
qbr = qbds_lbbuf.addRange(fieldNum(LedgerBalancesDimTrans, AccountNum));
qbr.value(SysQuery::value(LedgerDistribByAlg.OffsetAccountNum));
}
if (LedgerDistribByAlg.BaseAccountNum)
{
qbr = qbds_lbbuf.addRange(fieldNum(LedgerBalancesDimTrans, AccountNum));
qbr.value(SysQuery::value(LedgerDistribByAlg.BaseAccountNum));
}
qbds_lbbuf.joinMode(JoinMode::NoExistsJoin);
ds1 = strfmt("%1.%2", qbds_lb.name(), fieldName);
ds2 = strfmt("%1.%2", qbds_lbbuf.name(), fieldName);
queryExression = strfmt("(%2 != %1) && ((%2 == %1) || (!%1))", ds1, ds2 );
qbr = qbds_lbbuf.addRange(fieldId);
qbr.value(queryExression);
qR = new QueryRun(q);
// qR.reset();
while (qR.next())
{
// . . .
}
// . . .
Но оно не работает. Выдает сообщение "
Ошибка расширенного диапазона запроса: Ожидается правая круглая скобка рядом с 15"