开发者

How to compare Unicode characters in SQL server?

Hi I am trying to find all rows in my database (SQL Server) which have character é in their text by executing the following queries.

SELECT COUNT(*) FROM t_question WHERE patindex(N'%[\xE9]%',question) > 0;

SELECT COUNT(*) FROM t_question WHERE patindex(N'%[\u00E9]%',question) > 0;

But I found two problems: (a) Both of them are 开发者_如何学运维returning different number of rows and (b) They are returning rows which do not have the specified character.

Is the way I am constructing the regular expression and comparing the Unicode correct?

EDIT:

The question column is stored using datatype nvarchar. The following query gives the correct result though.

SELECT COUNT(*) FROM t_question WHERE question LIKE N'%é%';


Why not use SELECT COUNT(*) FROM t_question WHERE question LIKE N'%é%'?

NB: Likeand patindex do not accept regular expressions.

In the SQL Server pattern syntax [\xE9] means match any single character within the specified set. i.e. match \, x, E or 9. So any of the following strings would match that pattern.

  • "Elephant"
  • "axis"
  • "99.9"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜