LIKE with case-sensitive flash cards

I have 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;

It is assumed that all objects in the database have at least three consecutive capital symbols, however this does not seem to work, and I'm not quite sure why. I tried to list all characters explicitly, instead of specifying a range, but this did not solve the problem.

Sample data:

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

Required Conclusion:

name
---------
HTMLTable
+4
source share
2 answers

Try this instead:

LIKE '%[A-Z][A-Z][A-Z]%' COLLATE Latin1_General_Bin
+5
source

The following 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;
+2
source

Source: https://habr.com/ru/post/1693861/


All Articles