-- EXEC MIG_ITEM_USERS_SP
CREATE OR ALTER PROCEDURE MIG_ITEM_USERS_SP
AS
BEGIN
	DELETE FROM MIG_ITEM_USERS
	INSERT INTO MIG_ITEM_USERS

	SELECT	ZZ_ID, 
			AUT.LN_USER as AUTHOR, 
			ASM.LN_USER as ASSESSMENT_BY, 
			LCK.LN_USER as LOCKED_BY, 
			ITM.ENGINEER, -- Refers to "TCCOM001.ENGINEER" in 10.2.4 and "tccom001.emno" is "pd".
			ITM.PLANNER -- Refers to "TCCOM001.ENGINEER" in 10.2.4 and "tccom001.emno" is "pd".
	FROM ITEM ITM
	LEFT JOIN MIG_USERS AUT	ON AUT.USER_NAME =  ITM.AUTHOR
	LEFT JOIN MIG_USERS ASM	ON ASM.USER_NAME = ITM.ASSESSMENT_BY
	LEFT JOIN MIG_USERS LCK	ON LCK.USER_NAME = ITM.LOCKED_BY
	--LEFT JOIN MIG_USERS ENG	ON ENG.USER_NAME =  ITM.ENGINEER
	--LEFT JOIN MIG_USERS PLN	ON PLN.USER_NAME = ITM.PLANNER 
	WHERE ITM.OBJECT_TYPE = 0 --AND LEN(AUT.LN_USER) <10
END



