如果最后一个单词字符串与以“ I”,“ R”,“ N”结尾的字母匹配,则更新列

时间:2019-04-29 19:59:46

标签: teradata teradata-sql-assistant

UPDATE Tbls.Host SET 
HostActvTyp = CASE, HostPrevTyp = CASE WHEN LENGTH(RTRIM(LTRIM(HostCd)))=3 
                                 then 'CORE' 
                                 ELSE END,
HostActvTyp = CASE, HostPrevTyp = CASE WHEN SUBSTR(RTRIM(LTRIM(HSTHC)),4)='P' 
                                  then'PROSPECTING'
                                   ELSE END,
HostActvTyp = CASE, HostPrevTyp = CASE WHEN SUBSTR(RTRIM(LTRIM(HSTHC)),4)='I' 
                                 then'INDEPENDENT' 
                                 ELSE END,
HostActvTyp = CASE, HostPrevTyp = CASE WHEN SUBSTR(RTRIM(LTRIM(HSTHC)),4)='R' 
                                 then 'REACTIVE' 
                                 ELSE END,
HostActvTyp = CASE, HostPrevTyp = CASE WHEN SUBSTR(RTRIM(LTRIM(HSTHC)),4)='N' 
                                 then 'NEW' 
                                 ELSE END;

1 个答案:

答案 0 :(得分:1)

这似乎是您想要的。

UPDATE Tbls.Host set 
    HostPrevTyp = CASE WHEN LENGTH(TRIM(HostCd))=3 then 'CORE' 
                       WHEN SUBSTR(TRIM(HSTHC),4)='P' then'PROSPECTING' 
                       WHEN SUBSTR(TRIM(HSTHC),4)='I' then'INDEPENDENT' 
                       WHEN SUBSTR(TRIM(HSTHC),4)='R' then 'REACTIVE' 
                       WHEN SUBSTR(TRIM(HSTHC),4)='N' then 'NEW' 
                       ELSE 'UNKONWN' END
/*WHERE Clause maybe?*/
;