IF  EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TCRET_DECLARE_MAIN')
update  t_tctb_declare_main t
set
fbillno= (select fbillno from t_tcret_declare_main  a  where t.fmaindataid =a.fid ),
fbillstatus = (select fbillstatus from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fauditorid = (select fauditorid from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fauditdate = (select fauditdate from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
ftaxauthority = (select ftaxauthorityid from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fdeclaredate = (select fdeclaredate from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fdeclaretype = (select fdeclaretype from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fpaytype = (select fpaytype from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fpaydate = (select fpaydate from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fpaystatus = (select fpaystatus from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fdeclarer = (select fdeclarer from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fpayer = (select fpayer from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fdeclarestatus = (select fdeclarestatus from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fsbrq = (select fsbrq from  t_tcret_declare_main a  where t.fmaindataid =a.fid ),
fbqybtse = (select fbqybtsehj from  t_tcret_declare_main a  where t.fmaindataid =a.fid )
where t.fmaindataid  in ( select  fid from  t_tcret_declare_main b where t.fmaindataid =b.fid and t.fbillno <> b.fbillno ) and t.fnsrtype ='ccxws';

update t_tctb_declare_main set ftemplateid ='1153003674981797888' where fnsrtype ='ccxws' and ftemplateid <> '1153003674981797888';

update t_tctb_declare_main set fpaytype ='0' where fnsrtype ='ccxws' and fpaystatus='paid';