SQL Server转义下划线

时间:2020-03-05 18:38:34  来源:igfitidea点击:

如何逃脱下划线字符?

我正在编写类似以下where子句的内容,并希望能够在末尾找到_d的实际条目。

Where Username Like '%_d'

解决方案

回答

适用于SQL Server 2000的LIKE的T-SQL参考:

You can use the wildcard pattern matching characters as literal characters. To use a wildcard character as a literal character, enclose the wildcard character in brackets. The table shows several examples of using the LIKE keyword and the [ ] wildcard characters.

对于情况:

... LIKE '%[_]d'