CREATE OR ALTER FUNCTION [dbo].[MIG_CONTAINS_HIGH_ASCII_CHARS_Fn]
(
    @DATA NVARCHAR(4000)
)
RETURNS INT
AS
BEGIN
	DECLARE @STR_LENGTH INT
	DECLARE @INDEX INT
	--DECLARE @POS_ASCII_VAL INT
	SELECT @STR_LENGTH = LEN(@DATA)

	SET @INDEX = 1

	DECLARE @fieldsList varchar(8000)                        

	WHILE @INDEX <= @STR_LENGTH 
	BEGIN
		--SET @POS_ASCII_VAL = 
		IF ASCII(SUBSTRING(@DATA, @INDEX, 1)) > 127
			RETURN 1

		SET @INDEX = @INDEX + 1
	END

    RETURN 0
END

--SELECT dbo.MIG_CONTAINS_HIGH_ASCII_CHARS_Fn('Ø0.5" GULF COAST SEAL')
--SELECT dbo.MIG_CONTAINS_HIGH_ASCII_CHARS_Fn('0.5" GULF COAST SEAL')
--SELECT ZZ_ID, DOC_KEY, REVISION, dbo.MIG_CONTAINS_HIGH_ASCII_CHARS_Fn(STRING1), STRING1
--FROM DOC 
--WHERE 
--	--ZZ_ID > 100704 AND ZZ_ID < 179494 AND STRING1 LIKE '%GULF COAST SEAL%' 
--	dbo.MIG_CONTAINS_HIGH_ASCII_CHARS_Fn(STRING1) = 1
--ORDER BY ZZ_ID

--SELECT COUNT(*) 
--FROM DOC 
--WHERE dbo.MIG_CONTAINS_HIGH_ASCII_CHARS_Fn(STRING1) = 1

--SELECT ZZ_ID, DSET_KEY, REVISION, dbo.MIG_CONTAINS_HIGH_ASCII_CHARS_Fn(DSET_NAME), DSET_NAME
--FROM DATASET 
--WHERE 
--	--ZZ_ID > 100704 AND ZZ_ID < 179494 AND STRING1 LIKE '%GULF COAST SEAL%' 
--	dbo.MIG_CONTAINS_HIGH_ASCII_CHARS_Fn(DSET_NAME) = 1
--ORDER BY ZZ_ID
