05.06.2010, 09:34 | #1 |
Участник
|
Создание запроса программно
Задача определить корреспонденцию балансовых с забалансовыми счетами.
В плане счетов ввела галки Балансовый/Забалансовый. Идею условие с чем может корреспондировать на плане счетов не предлагать, по некоторым причинам не подходит. Пишу код X++: Query qryLTbl1; QueryRun qrunLTbl1; QueryBuildDataSource qbdsLTbl1; QueryBuildRange qbrOutBalance1; LedgerTable _LTbl1Q; QueryBuildDataSource qbdsLT1; QueryBuildRange qbrPeriod1; QueryBuildRange qbrPeriodType1; QueryBuildRange qbrType1; QueryBuildRange qbrAccountNum1; QueryBuildRange qbrD_C; QueryBuildRange qbrBalanceC1; LedgerTrans _LTQ1; QueryBuildDataSource qbdsLT2; LedgerTrans _LTQ2; QueryBuildRange qbrD_C2; QueryBuildDataSource qbdsLTbl2; QueryBuildRange qbrOutBalance2; LedgerTable _LTbl2Q; str 254 _periodLT; str 254 _periodCode; qryLTbl1 = new Query(); qbdsLTbl1 = qryLTbl1.addDataSource(tablenum(LedgerTable),'lbdt2'); qbrOutBalance1 = qbdsLTbl1.addRange(fieldnum(LedgerTable,OutBalance)); qbrOutBalance1.value(enum2str(NoYes::Yes)); qbdsLT1 = qbdsLTbl1.addDataSource(tablenum(LedgerTrans),'lbdt20'); qbdsLT1.fetchMode(JoinMode::INNERJOIN); qbdsLT1.relations(true); qbdsLT1.addLink(fieldnum(LedgerTrans, accountNum), fieldnum(LedgerTable, accountNum)); qbrPeriod1 = qbdsLT1.addRange(fieldnum(LedgerTrans,TransDate)); _periodLT = Date2str(fromdate,12,2,2,2,2,2)+'..'+Date2str(todate,12,2,2,2,2,2); qbrPeriod1.value(_periodLT); qbrPeriodType1 = qbdsLT1.addRange(fieldnum(LedgerTrans,PeriodCode)); qbrPeriodType1.value(enum2str(PeriodCode::Regular)); qbrD_C = qbdsLT1.addRange(fieldnum(LedgerTrans,Crediting)); qbrD_C.value(enum2str(NoYes::No)); qbdsLT2 = qbdsLT1.addDataSource(tablenum(LedgerTrans),'lbdt21'); qbdsLT2.fetchMode(JoinMode::INNERJOIN); qbdsLT2.relations(false); qbdsLT2.addLink(fieldnum(LedgerTrans, accountNum), fieldnum(LedgerTrans, accountNum)); qbdsLT2.addLink(fieldnum(LedgerTrans, BondBatch_RU), fieldnum(LedgerTrans, BondBatch_RU)); qbdsLT2.addLink(fieldnum(LedgerTrans, BondBatchTrans_RU), fieldnum(LedgerTrans, BondBatchTrans_RU)); qbrD_C2 = qbdsLT2.addRange(fieldnum(LedgerTrans,Crediting)); qbrD_C2.value(enum2str(NoYes::Yes)); qbdsLTbl2 = qbdsLT2.addDataSource(tablenum(LedgerTable),'lbdt211'); qbrOutBalance2 = qbdsLTbl2.addRange(fieldnum(LedgerTable,OutBalance)); qbrOutBalance2.value(enum2str(NoYes::No)); qbdsLTbl2.fetchMode(JoinMode::INNERJOIN); qbdsLTbl2.addLink(fieldnum(LedgerTrans, accountNum), fieldnum(LedgerTable, accountNum)); qrunLTbl1 = new QueryRun(qryLTbl1); while (qrunLTbl1.next()) { info ('11'); } Итоговый запрос выглядит так SELECT * FROM LedgerTable WHERE ((OutBalance = Да)) JOIN * FROM LedgerTrans WHERE LedgerTable.AccountNum = LedgerTrans.AccountNum AND LedgerTable.AccountNum = LedgerTrans.AccountNum AND ((TransDate>=01.05.10 AND TransDate<=30.06.10)) AND ((PeriodCode = Обычный)) AND ((Crediting = Нет)) JOIN * FROM LedgerTrans WHERE LedgerTrans.AccountNum = LedgerTrans.AccountNum AND LedgerTrans.BondBatch_RU = LedgerTrans.BondBatch_RU AND LedgerTrans.BondBatchTrans_RU = LedgerTrans.BondBatchTrans_RU AND ((Crediting = Да)) JOIN * FROM LedgerTable WHERE LedgerTrans.AccountNum = LedgerTable.AccountNum AND ((OutBalance = Нет)) |
|