-- EXEC MIG_ITEM_Sp
CREATE PROCEDURE MIG_ITEM_Sp
AS
BEGIN
	DELETE FROM MIG_ITEM

	INSERT INTO [MIG_ITEM]
	(
			[ZZ_ID]
           ,[CURRENCY]
           ,[ITEM_GROUP]
           ,[MANUFACTURERS]
           ,[PRODUCT_TYPE]
           ,[PRODUCT_CLASS]
           ,[PRODUCT_LINE]
           ,[SELECTION_CODE]
           ,[SIGNAL_CODE]
           ,[UNIT_OF_MEASURE]
           ,[UNIT_SET]
           ,[WAREHOUSE]
           ,[WEIGHT_UNIT]
	)
	SELECT 
			ITM.ZZ_ID, 
			CUR.TYPE_CODE AS CURRENCY,
			GRP.TYPE_CODE AS ITEM_GROUP,
			MNF.TYPE_CODE AS MANUFACTURERS,
			PDT.TYPE_CODE AS PRODUCT_TYPE,
			PDC.TYPE_CODE AS PRODUCT_CLASS,
			PDL.TYPE_CODE AS PRODUCT_LINE,
			SEL.TYPE_CODE AS SELECTION_CODE,
			SIG.TYPE_CODE AS SIGNAL_CODE,
			UOM.TYPE_CODE AS UNIT_OF_MEASURE,
			UNT.TYPE_CODE AS UNIT_SET,
			WAR.TYPE_CODE AS WAREHOUSE,
			WGT.TYPE_CODE AS WEIGHT_UNIT
	FROM ITEM ITM
	LEFT JOIN ZZ_UDCDTYPE CUR ON  CUR.VALUE_ID = ITM.CURRENCY				AND CUR.TYPE_NAME = 'UNCH_CURRENCY'
	LEFT JOIN ZZ_UDCDTYPE GRP ON  GRP.VALUE_ID = ITM.ITEM_GROUP 			AND GRP.TYPE_NAME = 'UNCH_ITEM_GROUP'
	LEFT JOIN ZZ_UDCDTYPE MNF ON  MNF.VALUE_ID = ITM.MANUFACTURERS			AND MNF.TYPE_NAME = 'UNCH_MANUFACTURERS'
	LEFT JOIN ZZ_UDCDTYPE PDT ON  PDT.VALUE_ID = ITM.PRODUCT_TYPE			AND PDT.TYPE_NAME = 'UNCH_PROD_TYPE' 
	LEFT JOIN ZZ_UDCDTYPE PDC ON  PDC.VALUE_ID = ITM.PRODUCT_CLASS			AND PDC.TYPE_NAME = 'UNCH_PRODUCT_CLASS'  
	LEFT JOIN ZZ_UDCDTYPE PDL ON  PDL.VALUE_ID = ITM.PRODUCT_LINE			AND PDL.TYPE_NAME = 'UNCH_PRODUCT_LINE' 
	LEFT JOIN ZZ_UDCDTYPE SEL ON  SEL.VALUE_ID = ITM.SELECTION_CODE			AND SEL.TYPE_NAME = 'UNCH_SEL_CODE'
	LEFT JOIN ZZ_UDCDTYPE SIG ON  SIG.VALUE_ID = ITM.SIGNAL_CODE			AND SIG.TYPE_NAME = 'UNCH_SIG_CODE'
	LEFT JOIN ZZ_UDCDTYPE UOM ON  UOM.VALUE_ID = ITM.UNIT_OF_MEASURE		AND UOM.TYPE_NAME = 'UNCH_UNIT_OF_MEASURE'
	LEFT JOIN ZZ_UDCDTYPE UNT ON  UNT.VALUE_ID = ITM.UNIT_SET				AND UNT.TYPE_NAME = 'UNCH_UNIT_SET'
	LEFT JOIN ZZ_UDCDTYPE WAR ON  WAR.VALUE_ID = ITM.WAREHOUSE				AND WAR.TYPE_NAME = 'UNCH_WAREHOUSE'
	LEFT JOIN ZZ_UDCDTYPE WGT ON  WGT.VALUE_ID = ITM.WEIGHT_UNIT			AND WGT.TYPE_NAME = 'UNCH_WEIGHT_UNIT'
	WHERE ITM.OBJECT_TYPE = 0
END




																	 
	       