
-- EXEC MIG_ITM_TRNS_HIST_Sp 
CREATE OR ALTER PROCEDURE MIG_ITM_TRNS_HIST_Sp 
AS
BEGIN
		DELETE FROM dbo.MIG_ITM_TRNS_HIST

		INSERT INTO dbo.MIG_ITM_TRNS_HIST
			(
				[ZZ_ID],
				COMPANY,
				TRANS_BY_EO_ID,
				ITEM_KEY,
				[MESSAGE],
				PROJECT,
				REVISION,
				SERIES_CODE,
				[STATUS],
				TRANS_BY_USER,
				TRANSFER_DATE,
				TRANSFER_TIME,
				UNIT_SEQUENCE,
				UPDATED_ON )
		
		SELECT dbo.ITM_TRNS_HIST.ZZ_ID,
		dbo.ITM_TRNS_HIST.COMPANY,
		dbo.MIG_ITM_TRNS_HIST_USERS.EO_ID,
		dbo.ITM_TRNS_HIST.ITEM_KEY,
		dbo.ITM_TRNS_HIST.MESSAGE,
		dbo.ITM_TRNS_HIST.PROJECT,
		dbo.ITM_TRNS_HIST.REVISION,
		dbo.ITM_TRNS_HIST.SERIES_CODE,
		dbo.ITM_TRNS_HIST.STATUS,
		dbo.MIG_USERS.LN_USER,
		dbo.ITM_TRNS_HIST.TRANSFER_DATE,dbo.ITM_TRNS_HIST.TRANSFER_TIME,
		dbo.ITM_TRNS_HIST.UNIT_SEQUENCE,
		dbo.ITM_TRNS_HIST.UPDATED_ON 
		from dbo.ITM_TRNS_HIST, dbo.MIG_ITEM_ONLY_1, dbo.MIG_ITM_TRNS_HIST_USERS, dbo.MIG_USERS
		where 	  dbo.ITM_TRNS_HIST.ITEM_KEY  =  dbo.MIG_ITEM_ONLY_1.ITEM_KEY  
			  AND dbo.MIG_ITM_TRNS_HIST_USERS.ZZ_ID  =  dbo.ITM_TRNS_HIST.ZZ_ID  
			  AND dbo.MIG_ITM_TRNS_HIST_USERS.TRANS_BY  =  dbo.MIG_USERS.USER_NAME
		order by dbo.ITM_TRNS_HIST.ITEM_KEY, dbo.ITM_TRNS_HIST.TRANSFER_DATE, dbo.ITM_TRNS_HIST.TRANSFER_TIME

END

