Using PATINDEX and a case-sensitive collation to search for upper-case letters in a string I noticed this was not yielding the desired result:
-- returns 1
SELECT PATINDEX('%[A-Z]%'
, 'abCde' COLLATE SQL_Latin1_General_Cp1_CS_AS);
however, specifying every letter, A-Z, does:
-- returns 3
SELECT PATINDEX('%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]%'
, 'abCde' COLLATE SQL_Latin1_General_Cp1_CS_AS);
Is my understanding of using a range in the first case incorrect? Why is the behaviour like this?
See Question&Answers more detail:os