Sql 当列类型为varchar时,根据数值筛选记录

Sql 当列类型为varchar时,根据数值筛选记录,sql,sql-server,Sql,Sql Server,我在一个数据类型为varchar的表中有一列存储版本号。我需要筛选并只选择小于等于5的版本号 输入 5.0.0.330 Eclair 5.0.0 5.0.0.591 5.0.0.405 6.0.0.522 4.0.2 7.1.0.205 5.0.0.592 2.3.4-ez 4.2.2-2013-12-11-V1.0 4.6.0.304 nubernel-2.6.35_v0.0.1 2.1-update1 2.3 5.0.0 4.0.2 2.3.4-ez 4.2.2-2013-12-11-V1

我在一个数据类型为varchar的表中有一列存储版本号。我需要筛选并只选择小于等于5的版本号

输入

5.0.0.330
Eclair
5.0.0
5.0.0.591
5.0.0.405
6.0.0.522
4.0.2
7.1.0.205
5.0.0.592
2.3.4-ez
4.2.2-2013-12-11-V1.0
4.6.0.304
nubernel-2.6.35_v0.0.1
2.1-update1
2.3
5.0.0
4.0.2
2.3.4-ez
4.2.2-2013-12-11-V1.0
4.6.0.304
2.1-update1
2.3
输出

5.0.0.330
Eclair
5.0.0
5.0.0.591
5.0.0.405
6.0.0.522
4.0.2
7.1.0.205
5.0.0.592
2.3.4-ez
4.2.2-2013-12-11-V1.0
4.6.0.304
nubernel-2.6.35_v0.0.1
2.1-update1
2.3
5.0.0
4.0.2
2.3.4-ez
4.2.2-2013-12-11-V1.0
4.6.0.304
2.1-update1
2.3
通过转换varchar列的第一个字符,我可以得到小于5的所有版本。但是我不知道如何在结果集中包含5.0.0版本

select distinct os_ver,substring(os_ver,1,1)  
from 
    dbo.mytable 
where 
    os_ver like '[0-9]%' and cast (substring(os_ver,1,1) as int) < 5
试试这个条件

select * from (
select '5.0.0.330' as a  union
select 'Eclair' union
select '5.0.0' union
select '5.0.0.591' union
select '5.0.0.405' union
select '6.0.0.522' union 
select '4.0.2' union
select '7.1.0.205' union
select '5.0.0.592' union
select '2.3.4-ez' union
select '4.2.2-2013-12-11-V1.0' union
select '4.6.0.304' union
select 'nubernel-2.6.35_v0.0.1' union
select '2.1-update1' union
select '2.3') b
where a <= '5.0.0' and ISNUMERIC(SUBSTRING(a, 1, 1)) = 1
从中选择*(
选择“5.0.0.330”作为联合体
选择“Eclair”联合
选择“5.0.0”联合
选择“5.0.0.591”联合
选择“5.0.0.405”联轴节
选择“6.0.0.522”联轴节
选择“4.0.2”联合
选择“7.1.0.205”活接头
选择“5.0.0.592”联合
选择“2.3.4-ez”接头
选择“4.2.2-2013-12-11-V1.0”接头
选择“4.6.0.304”活接头
选择“nubernel-2.6.35_v0.0.1”接头
选择“2.1-update1”联合
选择“2.3”)b

如果我的数据中有5.0版的话,一个完美的感谢也会起作用。@investiver\u乐意帮忙。我怀疑你只是想得太多了是的,我确实想得太多了。有时候解决办法真的很简单。再次感谢。
os_ver
5.0.0
4.0.2
2.3.4-ez
4.2.2-2013-12-11-V1.0
4.6.0.304
2.1-update1
2.3