IF OBJECT_ID(N'dbo.MIG_EO', N'U') IS NULL
	BEGIN	
		CREATE TABLE [dbo].[MIG_EO](
			[EO_ID]		[varchar](30) NOT NULL,
			[EXCEPTION]	[INT] NOT NULL
			CONSTRAINT PK_MIG_EO PRIMARY KEY ([EO_ID])
		) ON [PRIMARY]

	END


INSERT INTO [MIG_EO]
SELECT	DISTINCT  Eo.EO_ID,
		-- Get Exception of EoRej. if NULL, Get Eo Exception.
		COALESCE(EoRej.EXCEPTION, Eo.EXCEPTION) as EXCEPTION
FROM EO Eo
LEFT JOIN EO EoRej 
	ON	Eo.EO_ID = EoRej.EXCEPTION_EO AND
		EoRej.ROUTE_ID = 'REJECT' AND
		EoRej.EXCEPTION = 1  
WHERE Eo.ROUTE_ID <> 'REJECT'
