Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
iam searching item table & i use like statment
example
SQL
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
SQL
select * from item where itemname like '%[%'

so can any body help me
Posted
Updated 6-May-12 0:30am
v2
Comments
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: http://www.w3schools.com/sql/sql_wildcards.asp[^]

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

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

[/edit]
 
Share this answer
 
v2
Comments
Maciej Los 6-May-12 6:53am    
+5!
Mohamed Mitwalli 6-May-12 7:55am    
+5

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