SQL 关于字符转换成数值型的问题
来源:百度知道 编辑:UC知道 时间:2024/05/06 02:19:05
我想问的是
我有一串编号是字符串来的
我要把这个字符串转成数值型
然后用这个数值来排序
该怎么写
我的想法是
select cast(rno int) as bh from table1
order by bh
请问这样对不?
我有一串编号是字符串来的
我要把这个字符串转成数值型
然后用这个数值来排序
该怎么写
我的想法是
select cast(rno int) as bh from table1
order by bh
请问这样对不?
select cast(rno as int) as bh
from table1
where isnumeric(rno)=1
order by 1
isnumeric(rno)=1的目的是如果rno不能转换为数字就不转换,避免出错。
order by 1是按转换后的数字排序,即按cast(rno as int)排序,也可以写成order by cast(rno as int)