-- EXEC MIG_PROJECT_Sp
CREATE OR ALTER PROCEDURE MIG_PROJECT_Sp
AS
BEGIN
	
	DELETE FROM MIG_PROJECT

	INSERT INTO MIG_PROJECT 
	SELECT PROJ.PROJECT_ID , IsNull(PROJ_ID_CONF.PREF_VALUE, ALL_CONF.PREF_VALUE) AS RELEASE_AREA_PREF_VALUE
	FROM PROJECT PROJ
	LEFT JOIN PROJ_CONFIG PROJ_ID_CONF
		ON	PROJ_ID_CONF.PROJECT_ID = PROJ.PROJECT_ID AND
			PROJ_ID_CONF.CLASS_ID = '*' AND 
			PROJ_ID_CONF.PREF_NAME = 'RELEASE_AREA' 
	LEFT JOIN PROJ_CONFIG ALL_CONF
		ON	ALL_CONF.PROJECT_ID = '*' AND
			ALL_CONF.CLASS_ID = '*' AND 
			ALL_CONF.PREF_NAME = 'RELEASE_AREA' 

END