从国内识别国际订单

Identify international orders from domestic

我试图区分国内客户和国际客户。 我可以在 SQL 中完成,但我需要在 DB2 中完成。 在 SQL 我会说。

Select
DCSCRY,
case when ocrh.dcscry = '   ' then 'BLANK' else case when ocrh.dcscry <> 'US ' then 'Y' else '' end 
end as INTER
from ocrh

结果

DCSCRY   INTER

 US
 US 
 CA        Y
 CA        Y

对 DB2 有什么建议吗?

我认为您显示的 SQL 在任何地方都无效...也不符合您显示的结果...

when ocrh.dcscry = ' ' then 'BLANK'

但是您的结果不显示字符串 BLANK

DCSCRY   INTER
     

无论如何,您在发布的声明中有一个额外的 elsecase。正确的语法是

case
  when
  when
  else  
end

所以你的陈述应该是

Select
  DCSCRY,
  case 
    when ocrh.dcscry = '   ' then 'BLANK' 
    when ocrh.dcscry <> 'US ' then 'Y' 
    else '' 
  end as INTER
from ocrh