Код: Выделить всё
Create view
as select
SALDMOUN.DATESAL,
SALDMOUN.ATL_LASTDATE,
SALDMOUN.SCHETO,
SALDMOUN.DBSCHETO,
SALDMOUN.SUBOSSCH,
SALDMOUN.SUMS,
if(SALDMOUN.VIOB=1,'Деб','Кред')(FieldName='VidSaldo'),
BUHSCHET.NAME,
if(BUHSCHET.VIDSALD=0,' А', if(BUHSCHET.VIDSALD=1,' П', if(BUHSCHET.VIDSALD=2,' А-П', '???')))(FieldName=TipSchet),
if(BUHSCHET.BALANS=0,'Баланс', if(BUHSCHET.BALANS=1,'Забаланс', '???'))(FieldName=TipBalans),
if(SALDMOUN.TBLOS[1]=1 and IsValidall(tnkatorg1),katorg1.nrec,
if(SALDMOUN.TBLOS[2]=1 and IsValidall(tnkatorg2),katorg2.nrec,
if(SALDMOUN.TBLOS[3]=1 and IsValidall(tnkatorg3),katorg3.nrec,
if(SALDMOUN.TBLOS[4]=1 and IsValidall(tnkatorg4),katorg4.nrec,
if(SALDMOUN.TBLOS[5]=1 and IsValidall(tnkatorg5),katorg5.nrec,
if(SALDMOUN.TBLOS[6]=1 and IsValidall(tnkatorg6),katorg6.nrec,
Comp(0)))))))(FieldName=KauOrg),
if(SALDMOUN.TBLOS[1]=6 and IsValidall(tnbasedoc1),basedoc1.nrec,
if(SALDMOUN.TBLOS[2]=6 and IsValidall(tnbasedoc2),basedoc2.nrec,
if(SALDMOUN.TBLOS[3]=6 and IsValidall(tnbasedoc3),basedoc3.nrec,
if(SALDMOUN.TBLOS[4]=6 and IsValidall(tnbasedoc4),basedoc4.nrec,
if(SALDMOUN.TBLOS[5]=6 and IsValidall(tnbasedoc5),basedoc5.nrec,
if(SALDMOUN.TBLOS[6]=6 and IsValidall(tnbasedoc6),basedoc6.nrec,
Comp(0)))))))(FieldName=KauNomDoc),
if(SALDMOUN.TBLOS[1]=402 and IsValidall(tnSpKau1),SpKau1.nrec,
if(SALDMOUN.TBLOS[2]=402 and IsValidall(tnSpKau2),SpKau2.nrec,
if(SALDMOUN.TBLOS[3]=402 and IsValidall(tnSpKau3),SpKau3.nrec,
if(SALDMOUN.TBLOS[4]=402 and IsValidall(tnSpKau4),SpKau4.nrec,
if(SALDMOUN.TBLOS[5]=402 and IsValidall(tnSpKau5),SpKau5.nrec,
if(SALDMOUN.TBLOS[6]=402 and IsValidall(tnSpKau6),SpKau6.nrec,
Comp(0)))))))(FieldName=PKau1),
if(SALDMOUN.TBLOS[1]=403 and IsValidall(tnSpKau1),SpKau1.nrec,
if(SALDMOUN.TBLOS[2]=403 and IsValidall(tnSpKau2),SpKau2.nrec,
if(SALDMOUN.TBLOS[3]=403 and IsValidall(tnSpKau3),SpKau3.nrec,
if(SALDMOUN.TBLOS[4]=403 and IsValidall(tnSpKau4),SpKau4.nrec,
if(SALDMOUN.TBLOS[5]=403 and IsValidall(tnSpKau5),SpKau5.nrec,
if(SALDMOUN.TBLOS[6]=403 and IsValidall(tnSpKau6),SpKau6.nrec,
Comp(0)))))))(FieldName=PKau2),
if(SALDMOUN.TBLOS[1]=415 and IsValidall(tnSpKau1),SpKau1.nrec,
if(SALDMOUN.TBLOS[2]=415 and IsValidall(tnSpKau2),SpKau2.nrec,
if(SALDMOUN.TBLOS[3]=415 and IsValidall(tnSpKau3),SpKau3.nrec,
if(SALDMOUN.TBLOS[4]=415 and IsValidall(tnSpKau4),SpKau4.nrec,
if(SALDMOUN.TBLOS[5]=415 and IsValidall(tnSpKau5),SpKau5.nrec,
if(SALDMOUN.TBLOS[6]=415 and IsValidall(tnSpKau6),SpKau6.nrec,
Comp(0)))))))(FieldName=PKau3),
if(SALDMOUN.TBLOS[1]=KodKauV1 and IsValidall(tnSpKau1),SpKau1.nrec,
if(SALDMOUN.TBLOS[2]=KodKauV1 and IsValidall(tnSpKau2),SpKau2.nrec,
if(SALDMOUN.TBLOS[3]=KodKauV1 and IsValidall(tnSpKau3),SpKau3.nrec,
if(SALDMOUN.TBLOS[4]=KodKauV1 and IsValidall(tnSpKau4),SpKau4.nrec,
if(SALDMOUN.TBLOS[5]=KodKauV1 and IsValidall(tnSpKau5),SpKau5.nrec,
if(SALDMOUN.TBLOS[6]=KodKauV1 and IsValidall(tnSpKau6),SpKau6.nrec,
Comp(0)))))))(FieldName=PKau4),
if(SALDMOUN.TBLOS[1]=KodKauV2 and IsValidall(tnSpKau1),SpKau1.nrec,
if(SALDMOUN.TBLOS[2]=KodKauV2 and IsValidall(tnSpKau2),SpKau2.nrec,
if(SALDMOUN.TBLOS[3]=KodKauV2 and IsValidall(tnSpKau3),SpKau3.nrec,
if(SALDMOUN.TBLOS[4]=KodKauV2 and IsValidall(tnSpKau4),SpKau4.nrec,
if(SALDMOUN.TBLOS[5]=KodKauV2 and IsValidall(tnSpKau5),SpKau5.nrec,
if(SALDMOUN.TBLOS[6]=KodKauV2 and IsValidall(tnSpKau6),SpKau6.nrec,
Comp(0)))))))(FieldName=PKau5)
from SALDMOUN,
BUHSCHET,
katorg katorg1,
katorg katorg2,
katorg katorg3,
katorg katorg4,
katorg katorg5,
katorg katorg6,
basedoc basedoc1,
basedoc basedoc2,
basedoc basedoc3,
basedoc basedoc4,
basedoc basedoc5,
basedoc basedoc6,
SpKau SpKau1,
SpKau SpKau2,
SpKau SpKau3,
SpKau SpKau4,
SpKau SpKau5,
SpKau SpKau6
where ((SALDMOUN.SCHETO==BUHSCHET.SCHET
and SALDMOUN.SUBOSSCH==BUHSCHET.SUBSCH
and SALDMOUN.KAUOS[1]==katorg1.nrec
and SALDMOUN.KAUOS[2]==katorg2.nrec
and SALDMOUN.KAUOS[3]==katorg3.nrec
and SALDMOUN.KAUOS[4]==katorg4.nrec
and SALDMOUN.KAUOS[5]==katorg5.nrec
and SALDMOUN.KAUOS[6]==katorg6.nrec
and SALDMOUN.KAUOS[1]==basedoc1.nrec
and SALDMOUN.KAUOS[2]==basedoc2.nrec
and SALDMOUN.KAUOS[3]==basedoc3.nrec
and SALDMOUN.KAUOS[4]==basedoc4.nrec
and SALDMOUN.KAUOS[5]==basedoc5.nrec
and SALDMOUN.KAUOS[6]==basedoc6.nrec
and SALDMOUN.KAUOS[1]==SpKau1.nrec
and SALDMOUN.KAUOS[2]==SpKau2.nrec
and SALDMOUN.KAUOS[3]==SpKau3.nrec
and SALDMOUN.KAUOS[4]==SpKau4.nrec
and SALDMOUN.KAUOS[5]==SpKau5.nrec
and SALDMOUN.KAUOS[6]==SpKau6.nrec
))