Skip to content

Instantly share code, notes, and snippets.

@PartTimeLegend
Created October 14, 2016 11:07
Show Gist options
  • Select an option

  • Save PartTimeLegend/de3eca92cf1a31885369b86231453d1e to your computer and use it in GitHub Desktop.

Select an option

Save PartTimeLegend/de3eca92cf1a31885369b86231453d1e to your computer and use it in GitHub Desktop.
create function [dbo].[udf_ContainsNonASCIIChars](@string nvarchar(4000),@checkExtendedCharset bit )returns bit asbegin declare @pos int = 0; declare @char varchar(1); declare @return bit = 0; while @pos < len(@string) begin select @char = substring(@string, @pos, 1) if ascii(@char) < 32 or ascii(@char) > 126 begin if @checkExtendedCharset = 1 begin if ascii(@char) not in (9,124,130,138,142,146,150,154,158,160,170,176,180,181,183,184,185,186,192,193,194,195,196,197,199,200,201,202,203,204,205,206,207,209,210,211,212,213,214,216,217,218,219,220,221,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,248,249,250,251,252,253,254,255) begin select @return = 1; select @pos = (len(@string) + 1) end else begin select @pos = @pos + 1 end end else begin select @return = 1; select @pos = (len(@string) + 1) end end else begin select @pos = @pos + 1 end end return @return; end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment