SELECT
  zSubDiv.number as podr,
  Ltrim(zSubDiv.name) as name_podr,
  RTrim(Ltrim(zAnk.tab_num)) as tn,
  Ltrim(Person.surname) as f,
  Ltrim(Person.firstname) as i,
  Ltrim(Person.secondname) as o,
  Passport.gni as p_gni,
  Person.docserial as p_serial,
  Person.docnumber as p_num,
  LTrim(Person.docdealer) as p_dialer,
  Person.docdate as p_date,
  Person.birthday as date_r,
  Person.sex as pol,
  zAnk.jobbegin as date_rb,
  zAnk.jobend as date_uv,
  Address.postindex as ad_index,
  Region.sogni as ad_region,
  Address.region as ad_region,
  Address.regiontype as ad_region_t,
  Address.city as ad_city,
  Address.citytype as ad_city_t,
  Address.townname as ad_punkt,
  Address.towntype as ad_punkt_t,
  Address.street as ad_street,
  Address.streettype as ad_str_t,
  Address.house as ad_house,
  Address.constructi as ad_house2,
  Address.building as ad_korpus,
  Address.flat as ad_flat,
  zAnk.pf_id as strah_n,
  LTrim(OrgBase.inn) as inn_fl,
  Passport.gni as p_gni,
  Region.sogni as region,
  LTrim(zTipDol.name) as dolgnost,
  LTrim(BankAcc.account) as BankCard
from zfcac
  left join zSubDiv on (zSubDiv.subdiv_rn = zfCac.subdiv_rn)
  left join zAnk on (zAnk.ank_rn = zfCac.ank_rn)
  left join Person on (Person.orbase_rn = zAnk.orgbase_rn)
  left join Passport on (Passport.passport_rn = person.passport_rn)
  left join OrgBase on (OrgBase.rn = zAnk.orgbase_rn)
  left join Address on (zAnk.orgbase_rn = Address.orbase_rn)
  left join Region on (Address.region_rn = Region.region_rn)
  left join zTipDol on (zfCac.tipdol_rn = zTipDol.tipdol_rn)
  left join BankAcc on (zAnk.trn_orgto_rn = BankAcc.orbase_rn and zAnk.trn_bankto_rn = BankAcc.bankaccrn)
order by tn
