当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - Decode with Wildcard character

问题描述:

I'm trying to decode a column that contains names like 1.01 channel 1 and 2.04 channel 2

To do this i first used Decode based on only the first number. However now I need to further split channel 2 down.

I tried to use this:

Decode(Substr(ch.sales_chain_desc,1,4), '1*', 'Channel 1', '2.01', 'Channel 2 a', '2.10', 'Channel 2 b', '2.02', 'Channel 2 c', 'Other')

However it gave the wrong result. Is there any other character i should use instead of * (asterix)

网友答案:

it's probably better to use case in this... case:

CASE 
  WHEN ch.sales_chain_desc LIKE '1%' THEN 'Channel 1'
  WHEN ch.sales_chain_desc = '2.01' THEN 'Channel 2 a'
  WHEN ch.sales_chain_desc = '2.10' THEN 'Channel 2 b'
  WHEN ch.sales_chain_desc = '2.02' THEN 'Channel 2 c'
  ELSE 'Other'
END
分享给朋友:
您可能感兴趣的文章:
随机阅读: