Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --truncate table aip_sgoz_detail_${import_year};
- --insert into aip_sgoz_detail_${import_year}
- SELECT s.cul_parent contragent_inn, org.kpp,UPPER(COALESCE(org.full_name, u.full_name)) full_namE,
- org.grbs_inn, org.parentid grbsid,
- CASE WHEN s.cul_parent IN ('7838479881','7838489103') THEN 'КОМИТЕТ ПО ТРУДУ И ЗАНЯТОСТИ НАСЕЛЕНИЯ САНКТ-ПЕТЕРБУРГА' ELSE org.grbs_full_name END grbs_name,
- s.targetexpenseitemcode, t.np_code_name,t.fp_code_name,s.contragent_account,
- CASE
- WHEN s.targetexpenseitemcode IN (SELECT * FROM dwh_targetexpenseitemcode_aip) AND s.cvr NOT IN ('244')
- OR (s.targetexpenseitemcode='022E15305F' AND s.cvr='414' AND s.kosgu='310' AND s.cul_parent='7809025523')
- THEN 'Да' ELSE 'Нет'
- END priznak,--Признак совпадения целевой статьи (АИП)
- s.cvr,s.kosgu,
- SUM fin_aip, --финансирование АИП из бюджета
- S.FUND --Код фонда
- ,s.aip_name
- ,s.aip_code
- FROM (
- SELECT
- b.*
- FROM DWH_KF_LBO_AIP_KGNTV b
- Join dwh_organization_kgntv o ON (b.cul_parent=o.inn)
- WHERE b.YEAR=${import_year}
- AND ((b.cvr BETWEEN 200 AND 247 )
- OR ((b.cvr = '414' OR b.cvr = '412' OR b.cvr = '466') AND b.kosgu NOT IN ('297','298','299','530'))
- )
- AND (
- (b.targetexpenseitemcode NOT IN ('0210020830','0210020850','0220020820','0220020840','0510060500') AND o.inn='7832000076')
- OR
- o.inn<>'7832000076'
- )
- ) s
- Join DWH_KF_UL u ON s.cul_parent=u.code AND u.YEAR=${import_year}
- left Join (SELECT targetexpenseitemcode, fp_code, fp_code_name, np_code_name FROM dwh_targetexpenseitemcode_2020 ) t ON s.targetexpenseitemcode=t.targetexpenseitemcode
- left Join (SELECT * FROM dwh_organization_kgntv /*Where org_actual =1*/) org ON s.cul_parent=org.inn AND s.YEAR=${import_year}
- WHERE s.YEAR=${import_year} AND ( s.contragent_account NOT IN ('0171141','0295001'))
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement