INSERT INTO t_bcm_structofperiod_s (fid) select fid from t_bcm_structofperiod p where fnumber like 'M_M%' and flongnumber like 'Period!M_YearTotal!%' and not exists (select 1 from t_bcm_structofperiod_s s where p.fid=s.fid);
update t_bcm_structofperiod_s set flastperiod = 'M_M01' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M02') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M02' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M03') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M03' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M04') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M04' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M05') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M05' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M06') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M06' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M07') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M07' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M08') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M08' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M09') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M09' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M10') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M10' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M11') and flastperiod = ' ';
update t_bcm_structofperiod_s set flastperiod = 'M_M11' where fid in(select fid from t_bcm_structofperiod p where fnumber ='M_M12') and flastperiod = ' ';
update t_bcm_structofperiod_s set frelatednumber = 'M_M12',fisadjust = '1' where fid in(select fid from t_bcm_structofperiod p where fnumber in('M_M13','M_M14','M_M15','M_M16')) and frelatednumber = ' ';