SELECT t0.FBILLNO,t0.FID,t0e.FENTRYID
	,t1.FDATE,t0.FMOBILLNO
	,t0e.FFORECASTGROUP,t0e.FFORECASTGROUPFRIST
	,t1e.FFORECASTGROUPFRIST AS MOGROUPFRIST,t1e.FFORECASTGROUP AS MOGROUP,
--UPDATE t0e SET t0e.FFORECASTGROUP = t1e.FFORECASTGROUP
--    ,t0e.FFORECASTGROUPFRIST = 
	CASE 
        WHEN  CHARINDEX( '-',REPLACE( t1e.FFORECASTGROUP,'_','-') ,0) = 0 
        THEN t1e.FFORECASTGROUP 
        ELSE SUBSTRING(t1e.FFORECASTGROUP,0, CHARINDEX( '-',REPLACE( t1e.FFORECASTGROUP,'_','-') ,0)) 
    END
FROM T_PRD_PPBOM t0
	INNER JOIN T_PRD_PPBOMENTRY t0e on t0.FID = t0e.FID
	INNER JOIN T_PRD_MO t1 on t1.FID = t0.FMOID
	INNER JOIN T_PRD_MOENTRY t1e on t1e.FID = t0.FMOID
WHERE 1 = 1 AND t1e.FFORECASTGROUP != ''
    AND t0e.FFORECASTGROUP = ''
	AND t0e.FFORECASTGROUPFRIST != t1e.FFORECASTGROUPFRIST
ORDER BY t1.FDATE DESC