
CREATE PROCEDURE MIG_WAREHOUSES_Sp
AS
BEGIN
	 DELETE FROM dbo.MIG_WAREHOUSES
	 INSERT INTO dbo.MIG_WAREHOUSES

	 SELECT    Active,    TYPE_CODE,    SHORT_DESCR,   ORDER_NO    FROM  
	 (   SELECT ROW_NUMBER() OVER ( PARTITION BY UPPER(TYPE_CODE) ORDER BY VALUE_ID )  AS NonDuplicate ,   
			( CASE WHEN ORDER_NO < 0 then 0 ELSE 1 END ) as Active, 
			TYPE_CODE,    
			( CASE WHEN IsNull(SHORT_DESCR,'')= '' THEN NULL ELSE SHORT_DESCR END) as SHORT_DESCR,
			ORDER_NO  
			FROM  dbo.ZZ_UDCDTYPE    WHERE TYPE_NAME = 'UNCH_WAREHOUSE' 
	 ) as TmpTable WHERE NonDuplicate=1

END


