-- EXEC MIG_FOLDER_TYPE_Sp
CREATE PROCEDURE MIG_FOLDER_TYPE_Sp 
AS
BEGIN

	 DELETE from dbo.MIG_FOLDER_TYPE

	INSERT INTO MIG_FOLDER_TYPE

	SELECT	DTY.VALUE_ID, 
		CASE WHEN SFT.VALUE_ID IS NOT NULL THEN SFT.SHORT_DESCR
			 ELSE DTY.SHORT_DESCR
		END
		AS SHORT_DESCR,
		CASE WHEN SFT.VALUE_ID IS NOT NULL THEN SFT.LN_FOLDER_TYPE
			 WHEN LEN(DTY.SHORT_DESCR) > 30 THEN ''
			 ELSE DTY.SHORT_DESCR
		END
		AS LN_FOLDER_TYPE,

		CASE WHEN SFT.VALUE_ID IS NOT NULL THEN SFT.LN_DESC
			 ELSE DTY.SHORT_DESCR
		END
		AS LN_DESC,
		CASE WHEN SFT.VALUE_ID IS NOT NULL THEN 1
			 ELSE 0
		END
		AS IS_PD_MASTER_DATA
	FROM ZZ_UDCDTYPE DTY
	LEFT JOIN MIG_STANDARD_FOLDER_TYPE_MAPPING SFT
	ON SFT.SHORT_DESCR = DTY.SHORT_DESCR
	WHERE DTY.TYPE_NAME = 'FOLDER_TYPE' 
	ORDER BY DTY.SHORT_DESCR

	
END

