首页 > 解决方案 > Identify international orders from domestic

问题描述

I am trying to distinguish domestic customers from international customers. I can do it in SQL but I need to do it in DB2. In SQL I would say.

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

Result

DCSCRY   INTER

 US
 US 
 CA        Y
 CA        Y

Any advice in DB2?

标签: db2

解决方案


I don't think the SQL you've shown is valid anywhere...nor does it match the results you've shown...

when ocrh.dcscry = ' ' then 'BLANK'

But your results don't show the string BLANK

DCSCRY   INTER
     

In any event you've got an extra else and case in the statement you've posted. The correct syntax is

case
  when
  when
  else  
end

So your statement should be

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

推荐阅读