我正在使用Toad数据点,并且在转换列时遇到问题。我正在尝试将名为Rep
的包含Char(2)的列转换为整数。该表如下所示:
Row_ID Rep
1 00
2 01
3 02
4 03
我尝试了以下操作:
drop table if exists #my_table
select Row_ID, CONVERT(INT, Rep) as new_col
into
#my_table
from original_table
我也尝试过CAST(Rep as INT)
,但都给我错误Sybase Database Error: Data Exception -date type conversion is not possible
。
谢谢
答案 0 :(得分:1)
在Sybase中,类似这样的方法应该起作用:
select Row_ID,
(case when rep not like '%[^0-9]%' then cast(rep as int) end) as new_col
into #my_table
from original_table;
case
表达式正在检查列rep
仅包含数字-也就是说,它没有非数字字符。这不能处理负数,但是类似的逻辑可以处理负数。