What am I doing now?
mySQL searching for special characters like % 
Wednesday, February 27, 2008, 08:50 AM - General
Posted by Administrator
With most special characters in languages and, in this case, SQL, there is a way to escape them (which means have the character count for what it really is instead of the special meaning).

In mySQL, if you want to search for the % character, which means match anything and normally returns the entire table if that is all that is in the where clause, you would need to do this:

SELECT * FROM yourtable WHERE troublecolumn='%\%%'

That means find any number of characters, then a literal % and then any number of characters. This allows the literal % to be at the front, in the middle, or at the end of the searched column.

This same principal can be applied to the other special characters, like # for example:

SELECT * FROM yourtable WHERE troublecolumn='%\#%'

Enjoy!


add comment ( 5 views )   |  0 trackbacks   |  permalink   |   ( 3 / 352 )

<<First <Back | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Next> Last>>