问题
This doesn't return the expected results. Not sure how I can escape the left and right square brackets, so that PATINDEX takes them into account.
Any clues? Many thanks.
SELECT
PATINDEX('%[[SQLSERV]].DBNAME.DBO.[[[0-9a-zA-Z]]]%','ert[SQLSERV].DBNAME.DBO.[Table name]asdadsf')
This should return 3 but it returns 0.
回答1:
Apparently closing brackets don't need to be escaped:
SELECT
PATINDEX('%[[]SQLSERV].DBNAME.DBO.[[][0-9a-zA-Z _-]%','ert[SQLSERV].DBNAME.DBO.[Table name]asdadsf')
the above returns 4.
Also, we can't customise an escape character coupled with PATINDEX as we can do with LIKE.
来源:https://stackoverflow.com/questions/32403133/escape-square-brackets-in-patindex-with-sql-server