How does SQL Server Wildcard Character Range, eg [A-D], work with Case-sensitive Collation?

后端 未结 4 1135
别跟我提以往
别跟我提以往 2020-12-11 03:57

Can anyone explain the rules for how a wildcard character range, eg [A-D], works with a case-sensitive collation?

I would have thought the following

         


        
4条回答
  •  -上瘾入骨i
    2020-12-11 04:27

    Using a case-sensitive collation works for search strings that are not in a range e.g. this would work:

    SELECT *
      FROM #TEST_LIKE_Patterns
     WHERE (
            CharColumn LIKE 'A%' COLLATE Latin1_General_CS_AS
            OR CharColumn LIKE 'B%' COLLATE Latin1_General_CS_AS
            OR CharColumn LIKE 'C%' COLLATE Latin1_General_CS_AS
            OR CharColumn LIKE 'D%' COLLATE Latin1_General_CS_AS
           );
    

    ...but clearly that's not an acceptable approach!

    As others have suggested, use Latin1_General_BIN for ranges.

提交回复
热议问题