Search code examples
t-sqlunicodesql-like

t-sql LIKE and special characters


"[" is not classed a unicode character http://en.wikipedia.org/wiki/List_of_Unicode_characters (my guess) as to why this wouldn't work:

declare @v nvarchar(255)
set @v =  '[x]825' 
select 1 
where  @v like  '[x]825' 

Solution

  • [] defines a range of characters for a pattern match. It has special meaning in a LIKE statement. Here's the documentation for it.

    If you're looking for those characters explicitly, you'll need to escape them, like this:

    declare @v nvarchar(255)
    set @v =  '[x]825' 
    select 1 
    where  @v LIKE '![x]825' 
           ESCAPE '!'