SQL Server 中数字的通配符

2021-09-24 00:00:00 sql wildcard sql-server-2008 sql-server

如何在 SQL Server 'LIKE' 中匹配数字.

How to match numbers in SQL Server 'LIKE'.

SpaceName
------------ 
| New_Space_1
| .
| .
| New_Space_8 
| New_Space_9
| New_Space_10
| New_Space_11
| New_Space_SomeString
| New_Space_SomeString1

以上是我的表格内容.我只想获取以数字字符结尾的记录,即我想要从 New_Space_1New_Space_11 的记录.

Above is my table contents. I want to get only records ending with Numeric chars, ie I want the records from New_Space_1 to New_Space_11.

不想要 New_Space_SomeStringNew_Space_SomeString1

我有一些这样的查询.

SELECT SpaceName FROM SpaceTable
    WHERE SpaceName LIKE 'New_Space_%' 

但这会返回所有记录.

推荐答案

@SteveKass 的这个解决方案非常有效.

This solution from @SteveKass works perfect.

SELECT SpaceName FROM SpaceTable WHERE SpaceName LIKE 'New[_]Space[_]%' AND SpaceName NOT LIKE 'New[_]Space[_]%[^0-9]%' 

相关文章