update t_tctb_draft_main set fdatasource = 'hand' where (fdatasource is null or fdatasource = ' ') and fdraftpurpose = 'nssb';
update t_tctb_draft_main set fdrafttype = 'qysdsjb' where ftemplatetype = 'draft_qysdsjb' and fdraftpurpose = 'nssb';
update t_tctb_draft_main set fdrafttype = 'qysdsnb' where ftemplatetype = 'draft_qysdsnb' and fdraftpurpose = 'nssb';
update t_tctb_draft_main set fdrafttype = 'zzs' where ftemplatetype in ('draft_zzsybnsr','draft_zzsxgmnsr','draft_zzsybnsr_ybhz','draft_zzsybnsr_yz_zjg','draft_zzsybnsr_yz_fzjg') and fdraftpurpose = 'nssb';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_tctb_declare_main') 
update t_tctb_draft_main set fisdeclare = '1' where ftemplatetype = 'draft_qysdsjb' and fdraftpurpose = 'nssb' and 
(select count(fid) from t_tctb_declare_main d where d.forgid = forgid and d.fskssqq = fstartdate and d.fskssqz = fenddate and fnsrtype in ('qysdsjb','qysds_hdzs_jb')) > 0;

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_tctb_declare_main') 
update t_tctb_draft_main set fisdeclare = '1' where ftemplatetype = 'draft_qysdsnb' and fdraftpurpose = 'nssb' and
(select count(fid) from t_tctb_declare_main d where d.forgid = forgid and d.fskssqq = fstartdate and d.fskssqz = fenddate and fnsrtype in ('qysdsnb','qysdsnb_fzjg','qysds_hdzs_nb')) > 0;

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_tctb_declare_main') 
update t_tctb_draft_main d set fisdeclare = '1' where ftemplatetype = 'draft_zzsybnsr' and fdraftpurpose = 'nssb' and
(select count(fid) from t_tctb_declare_main d where d.forgid = forgid and d.fskssqq = fstartdate and d.fskssqz = fenddate and fnsrtype = 'zzsybnsr') > 0;

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_tctb_declare_main') 
update t_tctb_draft_main d set fisdeclare = '1' where ftemplatetype = 'draft_zzsxgmnsr' and fdraftpurpose = 'nssb' and
(select count(fid) from t_tctb_declare_main d where d.forgid = forgid and d.fskssqq = fstartdate and d.fskssqz = fenddate and fnsrtype = 'zzsxgmnsr') > 0;

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 't_tctb_declare_main') 
update t_tctb_draft_main d set fisdeclare = '1' where ftemplatetype = 'draft_zzsybnsr_ybhz' and fdraftpurpose = 'nssb' and
(select count(fid) from t_tctb_declare_main d where d.forgid = forgid and d.fskssqq = fstartdate and d.fskssqz = fenddate and fnsrtype = 'zzsybnsr_ybhz') > 0;