IF OBJECT_ID(N'dbo.MIG_EO_USERS', N'U') IS NULL
	BEGIN
		CREATE TABLE MIG_EO_USERS  (
			ZZ_ID INTEGER PRIMARY KEY,
			AUTHOR				varchar(9),
			REJECT_BY			varchar(9),
			REJECT_TO			varchar(9),
			RESPONSIBLE_USER	varchar(9)
		);
	END
GO


INSERT INTO MIG_EO_USERS

SELECT	ZZ_ID, 
		AUT.LN_USER as AUTHOR, 
		RBY.LN_USER as REJECT_BY, 
		RTO.LN_USER as REJECT_TO, 
		RPB.LN_USER as RESPONSIBLE_USER
FROM EO Eo
LEFT JOIN MIG_USERS AUT	ON AUT.USER_NAME =  Eo.AUTHOR
LEFT JOIN MIG_USERS RBY	ON RBY.USER_NAME =  Eo.REJECT_BY
LEFT JOIN MIG_USERS RTO	ON RTO.USER_NAME =  Eo.REJECT_TO
LEFT JOIN MIG_USERS RPB	ON RPB.USER_NAME =  Eo.RESPONSIBLE


GO
