【问题标题】:case and cast statement in TeradataTeradata 中的 case 和 cast 语句
【发布时间】:2015-01-11 01:28:20
【问题描述】:

我正在尝试在 Terdata 中编写 case 语句 If active = 'Yes' Then 1 elseif active = No Then 0 else NULL。我试过了

case  
  when cast(M_ACTIVE as integer)= 'YES' then '1' 
  when  cast(M_ACTIVE as integer) = 'NO' then '0' else  'null'  end

我收到错误字符串转换为数值失败。

【问题讨论】:

  • 您将 M_ACTIVE 转换为整数并将其与字符串“是”或“否”进行比较。因此出现错误

标签: sql teradata


【解决方案1】:

integer 既不能有 YES 也不能有 NO - 失去演员表:

case  
  when M_ACTIVE = 'YES' then 1
  when M_ACTIVE = 'NO' then 0
  else null
end

【讨论】:

  • 它仍然给我同样的错误。字符串转换为数值失败
【解决方案2】:
case  
  when M_ACTIVE = 'YES' then '1'
  when M_ACTIVE = 'NO' then '0'
  else 'null'
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-01
    • 2015-05-05
    • 2018-09-21
    • 2014-11-18
    • 2018-10-27
    • 2020-06-18
    • 2018-07-04
    • 2015-09-17
    相关资源
    最近更新 更多