-- EXEC MIG_MASKS_Sp 
CREATE OR ALTER PROCEDURE MIG_MASKS_Sp 
AS 
BEGIN
		EXEC MIG_MASK_FLD_MAPPING_Sp
		EXEC MIG_MASK_SEGMENTS_Sp
		EXEC MIG_MIG_MASKS_SEQ_CACHE_Sp
		EXEC MIG_MASK_CONDITIONS_Sp

		DELETE FROM MIG_MASKS

		INSERT INTO MIG_MASKS
		SELECT	'False', MASK_ID, MAP.LN_TABLE, MAP.LN_FIELD, -- CLASS_NAME, [KEY_NAME],  
				0 as orno, 
				LEN(MAX_MASK) AS keylength, 
				CASE WHEN DEFAULT_SIGN = 1 then 1 ELSE 2 END as pref, REF_MASK_ID, USER_MAX_MASK as [init], '' as pval, 
				CASE WHEN PRIMARY_SIGN = 1 then 1 ELSE 2 END as zpad , -- YES   -- PRIMARY_SIGN 1 => ELSE 0
				CONVERT(datetime, UPDATED_ON) AS updt,  2 as ursc, -- NO
				 '' as vodr, '' as nrgr, '' as seri
		FROM ZZ_MASK MSK
		JOIN MIG_MASK_FLD_MAPPING MAP
			ON MAP.CLASS_NAME = MSK.CLASS_NAME AND
				MAP.KEY_NAME = MSK.KEY_NAME

END


