Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从sql编号列中选择不同的_Sql_Sql Server 2008 - Fatal编程技术网

从sql编号列中选择不同的

从sql编号列中选择不同的,sql,sql-server-2008,Sql,Sql Server 2008,我有一个sql列,其中包含使用字母和数字的4位代码。我的问题是如何选择该列中以数字开头的所有行 示例数据如下: Codes afif eafea 5fea 6few cesa 25aa 我想选择第5fea行、第6FEA行、第25aa行 我试过做类似的事情 select left(Codes,4) from tableX where year = 2013 and Codes between 1 and 9 这应该起作用: SELECT Codes FROM TableX WHE

我有一个sql列,其中包含使用字母和数字的4位代码。我的问题是如何选择该列中以数字开头的所有行

示例数据如下:

Codes
afif
eafea
5fea
6few
cesa
25aa
我想选择第5fea行、第6FEA行、第25aa行

我试过做类似的事情

select 
   left(Codes,4)
from tableX
where year = 2013
   and Codes between 1 and 9
这应该起作用:

SELECT Codes FROM TableX WHERE LEFT(Codes, 1) LIKE '[0-9]' 

基本上,
code
的第一个字符必须在0到9之间才能返回。

如果您只想以任何数字开头,可以尝试

SELECT Codes FROM tableX where Codes LIKE '[0-9]%'

更多信息请参见

您的模式是什么??有多少个数字是从左开始固定的我刚试过,但仍然有U和B,因为一些奇怪的原因你的意思是你有以U或B开头的字符串吗?@TroyBryant不会返回以U或B开头的值。你添加了额外的百分比吗?+1,因为这是可搜索的,可以转换为范围搜索。是的,我有额外的百分比