CREATE OR ALTER PROCEDURE MIG_ANZ_VALIDATE_HIGH_ASCII_CHARS_Sp
AS 
BEGIN

	DECLARE @ITEM_STRING_1 INT
	DECLARE @ITEM_STRING_2 INT
	DECLARE @ITEM_STRING_3 INT
	DECLARE @ITEM_STRING_4 INT
	DECLARE @ITEM_STRING_5 INT
	DECLARE @ITEM_STRING_6 INT

	DECLARE @DOC_STRING_1 INT
	DECLARE @DOC_STRING_2 INT
	DECLARE @DOC_STRING_3 INT
	DECLARE @DOC_STRING_4 INT
	DECLARE @DOC_STRING_5 INT
	DECLARE @DOC_STRING_6 INT

	DECLARE @FOLDER_STRING_1 INT
	DECLARE @FOLDER_STRING_2 INT
	DECLARE @FOLDER_STRING_3 INT
	DECLARE @FOLDER_STRING_4 INT
	DECLARE @FOLDER_STRING_5 INT

	DECLARE @DATASET_DSET_NAME INT

	DECLARE @DATASET_STRING_1 INT
	DECLARE @DATASET_STRING_2 INT
	DECLARE @DATASET_STRING_3 INT
	DECLARE @DATASET_STRING_4 INT
	DECLARE @DATASET_STRING_5 INT

	DECLARE @EO_STRING_1 INT
	DECLARE @EO_STRING_2 INT
	DECLARE @EO_STRING_3 INT
	DECLARE @EO_STRING_4 INT
	DECLARE @EO_STRING_5 INT

	DECLARE @STATUS INT
	DECLARE @MESSAGE NVARCHAR(999)

	SET @STATUS = 0
	SET @MESSAGE = NULL

	SET @ITEM_STRING_1 = 0
	SET @ITEM_STRING_2 = 0
	SET @ITEM_STRING_3 = 0
	SET @ITEM_STRING_4 = 0
	SET @ITEM_STRING_5 = 0
	SET @ITEM_STRING_6 = 0

	SET @DOC_STRING_1 = 0
	SET @DOC_STRING_2 = 0
	SET @DOC_STRING_3 = 0
	SET @DOC_STRING_4 = 0
	SET @DOC_STRING_5 = 0
	SET @DOC_STRING_6 = 0

	SET @FOLDER_STRING_1 = 0
	SET @FOLDER_STRING_2 = 0
	SET @FOLDER_STRING_3 = 0
	SET @FOLDER_STRING_4 = 0
	SET @FOLDER_STRING_5 = 0

	SET @DATASET_DSET_NAME = 0

	SET @DATASET_STRING_1 = 0
	SET @DATASET_STRING_2 = 0
	SET @DATASET_STRING_3 = 0
	SET @DATASET_STRING_4 = 0
	SET @DATASET_STRING_5 = 0

	SET @EO_STRING_1 = 0
	SET @EO_STRING_2 = 0
	SET @EO_STRING_3 = 0
	SET @EO_STRING_4 = 0
	SET @EO_STRING_5 = 0

	-------- ITEM.STRING1 --------
	SELECT @ITEM_STRING_1 = COUNT(*)
	FROM ITEM 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(ITEM.STRING1) = 1

	-------- ITEM.STRING2 --------
	SELECT @ITEM_STRING_2 = COUNT(*)
	FROM ITEM 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(ITEM.STRING2) = 1

	-------- ITEM.STRING3 --------
	SELECT @ITEM_STRING_3 = COUNT(*)
	FROM ITEM 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(ITEM.STRING3) = 1

	-------- ITEM.STRING4 --------
	SELECT @ITEM_STRING_4 = COUNT(*)
	FROM ITEM 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(ITEM.STRING4) = 1

	-------- ITEM.STRING5 --------
	SELECT @ITEM_STRING_5 = COUNT(*)
	FROM ITEM 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(ITEM.STRING5) = 1

	-------- ITEM.STRING6 --------
	SELECT @ITEM_STRING_6 = COUNT(*)
	FROM ITEM 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(ITEM.STRING6) = 1

	-------- DOC.STRING1 --------
	SELECT @DOC_STRING_1 = COUNT(*)
	FROM DOC 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DOC.STRING1) = 1

	-------- DOC.STRING2 --------
	SELECT @DOC_STRING_2 = COUNT(*)
	FROM DOC 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DOC.STRING2) = 1

	-------- DOC.STRING3 --------
	SELECT @DOC_STRING_3 = COUNT(*)
	FROM DOC 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DOC.STRING3) = 1

	-------- DOC.STRING4 --------
	SELECT @DOC_STRING_4 = COUNT(*)
	FROM DOC 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DOC.STRING4) = 1

	-------- DOC.STRING5 --------
	SELECT @DOC_STRING_5 = COUNT(*)
	FROM DOC 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DOC.STRING5) = 1

	-------- DOC.STRING6 --------
	SELECT @DOC_STRING_6 = COUNT(*)
	FROM DOC 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DOC.STRING6) = 1

	-------- FOLDER.STRING1 --------
	SELECT @FOLDER_STRING_1 = COUNT(*)
	FROM FOLDER 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(FOLDER.STRING1) = 1

	-------- FOLDER.STRING2 --------
	SELECT @FOLDER_STRING_2 = COUNT(*)
	FROM FOLDER 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(FOLDER.STRING2) = 1

	-------- FOLDER.STRING3 --------
	SELECT @FOLDER_STRING_3 = COUNT(*)
	FROM FOLDER 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(FOLDER.STRING3) = 1

	-------- FOLDER.STRING4 --------
	SELECT @FOLDER_STRING_4 = COUNT(*)
	FROM FOLDER 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(FOLDER.STRING4) = 1

	-------- FOLDER.STRING5 --------
	SELECT @FOLDER_STRING_5 = COUNT(*)
	FROM FOLDER 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(FOLDER.STRING5) = 1

	-------- DATASET.DSET_NAME --------
	SELECT @DATASET_DSET_NAME = COUNT(*)
	FROM DATASET 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DATASET.DSET_NAME) = 1 AND LEN(DATASET.DSET_NAME) > 110

	-------- DATASET.STRING1 --------
	SELECT @DATASET_STRING_1 = COUNT(*)
	FROM DATASET 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DATASET.STRING1) = 1

	-------- DATASET.STRING2 --------
	SELECT @DATASET_STRING_2 = COUNT(*)
	FROM DATASET 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DATASET.STRING2) = 1

	-------- DATASET.STRING3 --------
	SELECT @DATASET_STRING_3 = COUNT(*)
	FROM DATASET 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DATASET.STRING3) = 1

	-------- DATASET.STRING4 --------
	SELECT @DATASET_STRING_4 = COUNT(*)
	FROM DATASET 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DATASET.STRING4) = 1

	-------- DATASET.STRING5 --------
	SELECT @DATASET_STRING_5 = COUNT(*)
	FROM DATASET 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(DATASET.STRING5) = 1

	-------- EO.STRING1 --------
	SELECT @EO_STRING_1 = COUNT(*)
	FROM EO 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(EO.STRING1) = 1

	-------- EO.STRING2 --------
	SELECT @EO_STRING_2 = COUNT(*)
	FROM EO 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(EO.STRING2) = 1

	-------- EO.STRING3 --------
	SELECT @EO_STRING_3 = COUNT(*)
	FROM EO 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(EO.STRING3) = 1

	-------- EO.STRING4 --------
	SELECT @EO_STRING_4 = COUNT(*)
	FROM EO 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(EO.STRING4) = 1

	-------- EO.STRING5 --------
	SELECT @EO_STRING_5 = COUNT(*)
	FROM EO 
	WHERE dbo.MIG_ANZ_CONTAINS_HIGH_ASCII_CHARS_Fn(EO.STRING5) = 1

	--------------------------------------------------------------------
	DELETE FROM MIG_ANZ_HIGH_ASCII_CHARS

	--------------------------------------------------------------------

	INSERT INTO MIG_ANZ_HIGH_ASCII_CHARS 
	(	
		[TABLE], 
		[FIELD], 
		[HAS_HIGH_ASCII_CHARS] 
	)
	VALUES
	( 'ITEM', 'STRING1', CASE WHEN @ITEM_STRING_1 > 0 THEN 1 ELSE 0 END ),
	( 'ITEM', 'STRING2', CASE WHEN @ITEM_STRING_2 > 0 THEN 1 ELSE 0 END ),
	( 'ITEM', 'STRING3', CASE WHEN @ITEM_STRING_3 > 0 THEN 1 ELSE 0 END ),
	( 'ITEM', 'STRING4', CASE WHEN @ITEM_STRING_4 > 0 THEN 1 ELSE 0 END ),
	( 'ITEM', 'STRING5', CASE WHEN @ITEM_STRING_5 > 0 THEN 1 ELSE 0 END ),
	( 'ITEM', 'STRING6', CASE WHEN @ITEM_STRING_6 > 0 THEN 1 ELSE 0 END ),

	( 'DOC', 'STRING1', CASE WHEN @DOC_STRING_1 > 0 THEN 1 ELSE 0 END ),
	( 'DOC', 'STRING2', CASE WHEN @DOC_STRING_2 > 0 THEN 1 ELSE 0 END ),
	( 'DOC', 'STRING3', CASE WHEN @DOC_STRING_3 > 0 THEN 1 ELSE 0 END ),
	( 'DOC', 'STRING4', CASE WHEN @DOC_STRING_4 > 0 THEN 1 ELSE 0 END ),
	( 'DOC', 'STRING5', CASE WHEN @DOC_STRING_5 > 0 THEN 1 ELSE 0 END ),
	( 'DOC', 'STRING6', CASE WHEN @DOC_STRING_6 > 0 THEN 1 ELSE 0 END ),

	( 'FOLDER', 'STRING1', CASE WHEN @FOLDER_STRING_1 > 0 THEN 1 ELSE 0 END ),
	( 'FOLDER', 'STRING2', CASE WHEN @FOLDER_STRING_2 > 0 THEN 1 ELSE 0 END ),
	( 'FOLDER', 'STRING3', CASE WHEN @FOLDER_STRING_3 > 0 THEN 1 ELSE 0 END ),
	( 'FOLDER', 'STRING4', CASE WHEN @FOLDER_STRING_4 > 0 THEN 1 ELSE 0 END ),
	( 'FOLDER', 'STRING5', CASE WHEN @FOLDER_STRING_5 > 0 THEN 1 ELSE 0 END ),

	( 'DATASET', 'DSET_NAME', CASE WHEN @DATASET_DSET_NAME > 0 THEN 1 ELSE 0 END ),

	( 'DATASET', 'STRING1', CASE WHEN @DATASET_STRING_1 > 0 THEN 1 ELSE 0 END ),
	( 'DATASET', 'STRING2', CASE WHEN @DATASET_STRING_2 > 0 THEN 1 ELSE 0 END ),
	( 'DATASET', 'STRING3', CASE WHEN @DATASET_STRING_3 > 0 THEN 1 ELSE 0 END ),
	( 'DATASET', 'STRING4', CASE WHEN @DATASET_STRING_4 > 0 THEN 1 ELSE 0 END ),
	( 'DATASET', 'STRING5', CASE WHEN @DATASET_STRING_5 > 0 THEN 1 ELSE 0 END ),

	( 'EO', 'STRING1', CASE WHEN @EO_STRING_1 > 0 THEN 1 ELSE 0 END ),
	( 'EO', 'STRING2', CASE WHEN @EO_STRING_2 > 0 THEN 1 ELSE 0 END ),
	( 'EO', 'STRING3', CASE WHEN @EO_STRING_3 > 0 THEN 1 ELSE 0 END ),
	( 'EO', 'STRING4', CASE WHEN @EO_STRING_4 > 0 THEN 1 ELSE 0 END ),
	( 'EO', 'STRING5', CASE WHEN @EO_STRING_5 > 0 THEN 1 ELSE 0 END )

	--------------------------------------------------------------------
	
END

-- EXEC MIG_ANZ_VALIDATE_HIGH_ASCII_CHARS_Sp 
-- SELECT * FROM MIG_ANZ_HIGH_ASCII_CHARS WHERE HAS_HIGH_ASCII_CHARS = 1

