如何在 SQL Server 2014 中查找所有以“S”开头但只有 4 个字符的名称

How to find all names that begin with “S” but only have 4 characters in SQL Server 2014

如何在 SQL Server 2014 中查找所有以 S 开头但只有 4 个字符的名称。

我尝试使用下面的 Where 子句,但它们不起作用。

Where Name Like 'S%%%' 
and 
Where Name Like 'S _ _ _' 
and
Where Name Like 'S***' 

感谢您的帮助

使用SQL LEN函数查看字段长度。 Link

试试这个:

Select * 
From MyTable
Where Name like 'S%' and LEN(Name) = 4

为什么要在图案之间放置空格?你只需删除空格就可以得到它

Where Name Like 'S___'