-- EXEC MIG_DOC_ONLY_2_Sp
CREATE OR ALTER PROCEDURE MIG_DOC_ONLY_2_Sp
AS
BEGIN
	DELETE FROM MIG_DOC_ONLY_2

	INSERT INTO MIG_DOC_ONLY_2
	(
		[DOC_KEY],
		[ZZ_ID_MAX]
	)
	SELECT DISTINCT 
		 STM.DOC_KEY
		,MAX(STM.ZZ_ID) AS "ZZ_ID_MAX" 
	FROM DOC STM 
	WHERE STM.OBJECT_TYPE = '8'
	GROUP BY STM.DOC_KEY

END
