Click to See Complete Forum and Search --> : Is it possible to tell a query to only return values that are all uppercase?


decibel
06-25-2007, 07:04 PM
Hello, my question is in the title. Is it possible to tell a query to only return values that are all uppercase?

so it would ignore "Pat", but would return "PAT".

thanks in advance

bubbisthedog
06-26-2007, 09:39 AM
Just include the field name in the where (or and) clause and compare it to the uppercase version of it:
WHERE field = upper(field)

decibel
06-26-2007, 12:42 PM
Thanks, it works great.

A note though on my version of mysql, i had to do it like this:

SELECT *
FROM colors
WHERE code LIKE BINARY UPPER( code )

Thanks again

bubbisthedog
06-26-2007, 01:42 PM
You're welcome. May I ask what version of MySQL you're using?

decibel
06-26-2007, 01:44 PM
4.0.25-standard, is the version the cause?

bubbisthedog
06-26-2007, 02:33 PM
dup

bubbisthedog
06-26-2007, 02:35 PM
Honestly, I didn't test it before offering my solution. Perhaps that version compares strings case-insensitive by default.

mattyblah
06-28-2007, 12:11 AM
please read up on collation. don't know if its sql server specific standard, but each db implementation should have their way of handling that.

bubbisthedog
06-28-2007, 08:36 AM
please read up on collation. don't know if its sql server specific standard, but each db implementation should have their way of handling that.
They're using MySQL, not SQL Server. I did come to find out that MySQL 4.0.25 standard is case-insensitive by default when comparing strings. Adding the BINARY keyword forces case-sensitivity.

http://dev.mysql.com/doc/refman/4.1/en/cast-functions.html

decibel
06-28-2007, 12:45 PM
Thanks bubbis, that is good to know