sql-serverpatindex

SQL Server PATINDEX returning a value when it shouldn't


Azure SQL Server 2017

Status Field Value:

1796-NM_IndiatimesMumbai_Daily has run

Statement:

PATINDEX('%[MED]%', Status COLLATE SQL_Latin1_General_CP1_CS_AS)

Returns

7

Why? I thought I was looking for an exact match on "MED" in all caps, so I would expect 0. I apparently don't have my pattern syntax correct.


Solution

  • Because like combined with square brackets [] searches for any character between the brackets. Is you remove the brackets Like '%MED%'

    It works asyou expect