Click here to Skip to main content
15,939,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
iam searching item table & i use like statment
declare @x nvarchar(1000)
select @x='ddd'

select * from item where lower(itemname) like lower(@x)+'%'
it work fien no problem
but if the item name contain [ it doesn't appear in the search
eban when i wrote this is statement no result
select * from item where itemname like '%[%'

so can any body help me
Updated 6-May-12 0:30am
Maciej Los 6-May-12 6:30am    
Code tags added
OriginalGriff 6-May-12 6:48am    
Answer updated

1 solution

It's because LIKE is a simple Regex processor, and '[' introduces a sequence of characters:
...LIKE 'x[abc]x' would match any of 'xax', 'xbx' or 'xcx' but would not match 'xdx'

See here:[^]

I don't know how you get round it though...

Oh yes I do:
SELECT * FROM item WHERE itemname LIKE '%[[]%'

Share this answer
Maciej Los 6-May-12 6:53am    
Mohamed Mitwalli 6-May-12 7:55am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900