Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - Sql query like operator with special characters

We want to allow all below special characters in search query based on which results should be available to end user. so we enter all below values in one column itself and now want to run sql query with Like operator.

  • !@#$%^&*()-_=+[]{}\|;':",./<>?

I looked for all possible solution like ESCAPE character, square bracket & so on. But it only works till

select * from table where title like '!@#$%[^]' ESCAPE '\'

As soon as i add '&', no rows are returned.

It seems i am missing something here.

like image 221
Manish Joisar Avatar asked Mar 23 '26 01:03

Manish Joisar


1 Answers

Try this simple way using regular expression as follows:

SELECT * FROM <YourTable>
WHERE <YourColumn> LIKE '%[!@#$%^&*()-_=+{}\|;'':",./[<>?]%' OR <YourColumn> LIKE '%]%';

Note that ] had to be taken separately so that it doesn't end the regular expression.

like image 162
Chaos Legion Avatar answered Mar 24 '26 21:03

Chaos Legion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!