使用CASE语句在Teradata中创建新列

时间:2019-01-29 04:10:12

标签: sql teradata teradata-sql-assistant

我正在尝试使用CASE语句在Teradata中的表中创建新列

我正在尝试从CASE语句基于表中的原始列ID_Number创建一个名为ID_Number_Mod的新列。下面是我的代码

alter table Table_A
add  (case
when char_length(cast(cast(ID_Number as bigint) as varchar(50)))=12 then cast('999000' as char(6)) || cast(cast( substr(cast(cast(ID_Number as bigint) as char(12)), 4, 12) as bigint) as char(15))
else ID_Number end) as ID_Number_Mod float;

我收到以下语法错误

  

”预期类似于名称或Unicode分隔标识符   在'('和'case'关键字之间

1 个答案:

答案 0 :(得分:1)

尝试将查询更改为

alter table Table_A

将ID_Number_Mod添加为(大小写 当char_length(cast(cast(cast(ID_Number as bigint)as varchar(50)))= 12时,则强制转换('999000'as char(6))|| cast(cast(substr(cast(cast(cast(ID_Number as bigint)as char(12)),4,12)as bigint)as char(15)) 其他ID_Number结尾);