Find non-ASCII characters in varchar columns using SQL Server

前端 未结 8 1567
遥遥无期
遥遥无期 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:45

    Here is a solution for the single column search using PATINDEX.
    It also displays the StartPosition, InvalidCharacter and ASCII code.

    select line,
      patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,Line) as [Position],
      substring(line,patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,Line),1) as [InvalidCharacter],
      ascii(substring(line,patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,Line),1)) as [ASCIICode]
    from  staging.APARMRE1
    where patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,Line) >0
    

提交回复
热议问题