select
 RTrim(Ltrim(zAnk.tab_num)) as tab_num,
 LTrim(RTrim(zfCac.fcac_num)) as num_ls,
 AllTrim(zSostZat.nick) as src,
 sootv_nu.vid_amba as amba_vid,
 substr(alltrim(str(zHis.month))+'.'
      +alltrim(str(zHis.year)),1,7) as month_nach,
 substr(alltrim(str(zHis.monthfor))+'.'
      +alltrim(str(zHis.yearfor)),1,7) as month_prin,
 alltrim(subst(zHisSp.value,2,12)) as nrv,
 alltrim(subst(zHisSp.value,1,1)) as ed_izm,
 zHis.sum as sum
from zHis
left join zAnk on (zAnk.ank_rn = zHis.ank_rn)
left join zfCac on (zfCac.fcac_rn = zHis.fcac_rn)
left join zfCacCh on (zfCacCh.fcacbs_rn = zfCac.fcac_rn)
left join zSostZat on (zSostZat.sostzat_rn = zfCacCh.sostzat_rn)
left join sootv_nu on (sootv_nu.rn = zHis.snu_rn)
left join zHisSp on (zHisSp.his_rn = zHis.his_rn
                      and zHisSp.code = 'WRK')
where
 zHis.sum <> 0 and
 (zHis.year between 2007 and 2008) and
order by tab_num, num_ls, month_nach, month_prin
