1

"[" 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' 
pirho
  • 11,565
  • 12
  • 43
  • 70
bizl
  • 1,535
  • 2
  • 12
  • 21

2 Answers2

3

[] 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 '!'
womp
  • 115,835
  • 26
  • 236
  • 269
1

[x] has a specific meaning to SQL server. The brackets are used for very basic regular expressions. SO what you are searching for is where the first character contains the letter X and of course that isn't the first character in your variable.

It is best not use like unless you intend to havea awildcard and it is a bad practice to have a wildcard be the first character as it makes the query use a table scan instead of an index.

HLGEM
  • 94,695
  • 15
  • 113
  • 186