Question

"[" 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' 
Was it helpful?

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 '!'

OTHER TIPS

[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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top