SQL Server, combining % and [] wildcards in LIKE statement

萝らか妹 提交于 2019-11-30 14:03:58

Like pattern matching is very limited, it does not allow for normal regular expressions.

See here for details.

For your needs use:

WHERE ColumnName LIKE '[a-z]%[0-9]'

This will match any letter followed by anything, followed by a number. SQL will enforce that the letter and number are at the two ends of the string because there is no pattern or literal character before or after our [] match set.

If you want to use Regex and have permissions, you can write a user defined function to give yourself access to the Regular Expressions parser on the SQL server's .NET CLR:

http://msdn.microsoft.com/en-us/magazine/cc163473.aspx (SQL 2005 and higher)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!