Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LIKE with case sensitive wildcards

I've got the following query:

SELECT *
FROM sys.objects AS O
WHERE O.is_ms_shipped = 0
AND O.name LIKE '%[A-Z][A-Z][A-Z]%' COLLATE Latin1_General_CS_AS;

This is supposed to find all objects within the database that have at least three consecutive capital characters, however it doesn't seem to work and I'm not really sure why. I've tried to list all characters explicitly instead of specifying range, but it didn't solve the problem.

Sample data:

name
---------
HTMLTable
HtmlTable

Desired output:

name
---------
HTMLTable
like image 888
Evaldas Buinauskas Avatar asked Mar 07 '23 20:03

Evaldas Buinauskas


2 Answers

Try this instead:

LIKE '%[A-Z][A-Z][A-Z]%' COLLATE Latin1_General_Bin
like image 126
t-clausen.dk Avatar answered Mar 21 '23 07:03

t-clausen.dk


The below code should work -

SELECT name
FROM sys.objects AS O
WHERE O.is_ms_shipped = 0
AND O.name LIKE '%[ABCDEFGHIJKLMNOPQRSTUVWXYZ][ABCDEFGHIJKLMNOPQRSTUVWXYZ][ABCDEFGHIJKLMNOPQRSTUVWXYZ]%' COLLATE Latin1_General_CS_AS;
like image 44
Abhishek Avatar answered Mar 21 '23 06:03

Abhishek