IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCRET_ACCRUAL_DRAFT')
insert
	into
	t_tpo_declare_main_tsd(fid,
	fbillno,
	fbillstatus,
	fcreatorid,
	fmodifierid,
	fauditorid,
	fauditdate,
	fmodifytime,
	fcreatetime,
	forgid,
	ftemplatetype,
	fskssqq,
	fskssqz,
	faccountorg,
	faccountsettype,
	ftaxsystem,
	faccrualplan,
	faccrualdate,
	fisxxwlqy,
	fjtynsesum,
	fpzhc
	)
select
	fid,
	fdraftno,
	fbillstatus,
	fcreatorid,
	fmodifierid,
	fauditorid,
	fauditdate,
	fmodifytime,
	fcreatetime,
	ftaxorg,
	fdrafttype,
	fskssqq,
	fskssqz,
	faccountorg,
	'1',
	1,
	faccrualplan,
	faccrualdate,
	fisxxwlqy,
	fjtynsesum,
	fpzhc
from
	t_tcret_accrual_draft a
where
	not exists (
	select
		fid
	from
		t_tpo_declare_main_tsd b
	where
		a.ftaxorg = b.forgid
		and a.fdrafttype = b.ftemplatetype
		and a.fskssqq = b.fskssqq
		and a.fskssqz = b.fskssqz);

-- 更新税种
update t_tpo_declare_main_tsd set ftaxtype = 8 where ftemplatetype = 'yhs';
update t_tpo_declare_main_tsd set ftaxtype = 7 where ftemplatetype = 'fcs';
update t_tpo_declare_main_tsd set ftaxtype = 9 where ftemplatetype = 'cztdsys';
update t_tpo_declare_main_tsd set ftaxtype = 11 where ftemplatetype = 'ccs';
update t_tpo_declare_main_tsd set ftaxtype = 18 where ftemplatetype = 'hjbhs';