CREATE PROCEDURE MIG_DOC_TYPE_Sp
AS
BEGIN

	 DELETE from dbo.MIG_DOC_TYPE

	INSERT INTO MIG_DOC_TYPE

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

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

END



-- EXEC MIG_DOC_TYPE_Sp
