>*------------------------------------------------------ >*AC_NO | AC_LEVEL | OB_DR | OB_CR >*------------------------------------------------------ >1 | 1 | | | >1-01 | 2 | | | >1-01-001 | 3 | | | >1-01-001-001 | 4 | | | >1-01-001-001-00001 | 5 | 500.00 | | >1-01-001-001-00002 | 5 | 400.00 | | >1-01-001-001-00003 | 5 | | 300.00 | >1-01-001-002 | 4 | | | >1-01-001-002-00001 | 5 | 100.00 | | >1-01-001-002-00002 | 5 | 600.00 | | >1-01-002 | 3 | | | >1-01-002-001 | 4 | | | >1-01-002-001-00001 | 5 | 800.00 | | >1-01-002-001-00002 | 5 | | 600.00 | > > > >*(Dashes are not part of Data) >>Only ac_level = 5 can have the data. Which then i update to parent a/c.
> Trial Balance Should have >*------------------------------------------------------ >*AC_NO | AC_LEVEL | OB_DR | OB_CR >*------------------------------------------------------ >1 | 1 |2400.00 | 900.00 | >1-01 | 2 |2400.00 | 900.00 | >1-01-001 | 3 |1600.00 | 300.00 | >1-01-001-001 | 4 | 900.00 | 300.00 | >1-01-001-002 | 4 | 700.00 | | >1-01-002 | 3 | 800.00 | 600.00 | >1-01-002-001 | 4 | 800.00 | 600.00 | >>The following code is doing fine to get this result. But problem is that when i run for first time it just update upto level 4.
>local lcSql ,; > lcAcNo ,; > lnAcLen,; > lcLvl ,; > lnObDr ,; > lnObCr >* Vmfc is view on SQLExpress >text to lcSql noshow > select * from Vmfc order by ac_level desc, ac_no desc >endtext >* >if SQLExec(hConn,lcSql, 'mfc') < 0 > return >endif >* You don't need parameters when you pass constants: >text to lcSql noshow > update acc_mf > set ob_dr = 0, ob_cr = 0 > where ac_level < '5' >endtext >=SQLExec(hConn, lcSql) >* >select mfc >go top >do while !eof() and ac_level != '1' > lcLvl = ac_level > do while !eof() and ac_level = lcLvl > lcAcNo = getPrntAC(mfc.ac_no) && Returns Parent A/C Code > lnAcLen= len(lcAcNo) > lnObDr = 0 > lnObCr = 0 > do while !eof() and ac_level + left(ac_no, lnAcLen) = lcLvl + lcAcNo > lnObDr = lnObDr + mfc.ob_dr > lnObCr = lnObCr + mfc.ob_cr > skip > enddo >*/ This block has the problem > text to lcSql noshow > update acc_mf > set ob_dr = ob_dr + ?lnObDr, > ob_cr = ob_cr + ?lnObCr > where ac_level < '5' > and ac_no = ?lcAcNo > endtext > =SQLExec(hConn, lcSql) >*// > select mfc > enddo >enddo >* >use in mfc >You always must check the result of SQLEXEC(), try this and tell us the result:
...... text to lcSql noshow update acc_mf set ob_dr = ob_dr + ?lnObDr, ob_cr = ob_cr + ?lnObCr where ac_level < '5' and ac_no = ?lcAcNo endtext IF SQLExec(hConn, lcSql) < 0 AERROR(laError) MessageBox([Can not update table ] +laError[1,2]) ENDIF ....