Finding %, _ and other Special Characters in SQL

Less than one minute read time.

I have just spent a frustrating few minutes trying to quickly find where '%' codes are used in translations. Of course '%' is a special wild card character in SQL. The same is true for '_' and other characters.

Don't do:

select capt_code, capt_family
from custom_captions
where capt_code like '%%%'

This gives nonsense results.

But either of these will work to find the data

select capt_code, capt_family
from custom_captions
where capt_code like '%[%]%'

OR

select capt_code, capt_family
from custom_captions
where capt_code like '%\%%' escape '\'

Parents
  • How do you query for strings starting with "c"?

    e.g. `where=Entity_companyId eq '11' and Entity_attribute LIKE '%case'`

    I'm aware `%c` has a special meaning in C so the response to that query replaces "%c" with some odd character but escaping it doesn't really make it better.

    e.g. `where=Entity_companyId eq '11' and Entity_attribute LIKE '%\case'` returns all entries, ignoring the company ID clause.

    Thank you.

Comment
  • How do you query for strings starting with "c"?

    e.g. `where=Entity_companyId eq '11' and Entity_attribute LIKE '%case'`

    I'm aware `%c` has a special meaning in C so the response to that query replaces "%c" with some odd character but escaping it doesn't really make it better.

    e.g. `where=Entity_companyId eq '11' and Entity_attribute LIKE '%\case'` returns all entries, ignoring the company ID clause.

    Thank you.

Children
No Data