我想从表中只获得大于10的数值
select col1 from mytable
col1
----
5.78
14.5
14.67
12
10.10 VERIFIED
15.3%
10
10.0
6.89
TNT
我想得到这些结果:
col1
----
14.5
14.67
12
10.10
15.3
10
10.0
答案 0 :(得分:2)
Declare @YourTable table (Col1 varchar(50))
Insert Into @YourTable values
('5.78'),
('14.5'),
('14.67'),
('12'),
('10.10 VERIFIED'),
('15.3%'),
('10'),
('10.0'),
('6.89'),
('TNT')
Select Col1
,Value = Left(col1,patindex('%[0-9] %',replace(col1,'%',' ')+' '))
From @YourTable
Where cast(Left(col1,patindex('%[0-9] %',replace(col1,'%',' ')+' ')) as money)>=10
返回
Col1 Value
14.5 14.5
14.67 14.67
12 12
10.10 VERIFIED 10.10
15.3% 15.3
10 10
10.0 10.0
答案 1 :(得分:0)
SQL:
Select col1 from mytable where ISNUMERIC(col1) = 1 and ROUND(col1, 0) >= 10
答案 2 :(得分:0)
SQL(假设数据类型是非数字类型):
Select col1
from mytable
where col1 >= 10
and IsNumeric(col1) = 1