I am trying use PATINDEX, but this simple example returns a match where I would not expect one. What am I missing, please?
SELECT PATINDEX('%[olzzzz]%', 'W3Schoolscom') position;
position
6
I would expect 0 since the pattern 'olzzzz' doesn't exist in the string. I get the same result from both SQL Server Management Studio on my laptop and from w3schools Website tutorial.
Using the square brackets matches any of the characters within the brackets so in this case the first match is o. If you want to find the string olzzzz then use '%olzzzz%'.