Find non-ASCII characters in varchar columns using SQL Server

前端 未结 8 1565
遥遥无期
遥遥无期 2020-12-02 14:38

How can rows with non-ASCII characters be returned using SQL Server?
If you can show how to do it for one column would be great.

I am doing something like this

8条回答
  •  温柔的废话
    2020-12-02 14:51

    This script searches for non-ascii characters in one column. It generates a string of all valid characters, here code point 32 to 127. Then it searches for rows that don't match the list:

    declare @str varchar(128)
    declare @i int
    set @str = ''
    set @i = 32
    while @i <= 127
        begin
        set @str = @str + '|' + char(@i)
        set @i = @i + 1
        end
    
    select  col1
    from    YourTable
    where   col1 like '%[^' + @str + ']%' escape '|'
    

提交回复
热议问题