Querying a SQL Server 2008 table to find values in a column containing Unicode characters

前端 未结 3 1389
深忆病人
深忆病人 2020-12-16 08:11

I\'ve run into a problem in a project I\'m working on: some of the string values in a specific SQL Server 2008 table column contain Unicode characters. For example, instead

3条回答
  •  -上瘾入骨i
    2020-12-16 08:45

    SELECT *
    FROM your_table
    WHERE your_column LIKE N'%[^ -~]%' collate Latin1_General_BIN
    

    finds all strings that contain one or more characters within ASCII characters 32-126.

    I thought the purpose was to find strings where ASCII characters are not in the range 32-126?

    NOT is possible with LIKE. Wouldn't this work?

    SELECT *
    FROM your_table
    WHERE your_column NOT LIKE N'%[^ -~]%'
    

    No collate required.

提交回复
热议问题