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:
Likeandpatindexdo not accept regular expressions.In the SQL Server pattern syntax
[\xE9]means match any single character within the specified set. i.e. match\,x,Eor9. So any of the following strings would match that pattern.