2014-09-19 48 views
0

我試圖解碼包含像1.01 channel 12.04 channel 2解碼與通配符

名稱爲此列我只基於第一個號碼第一次使用解碼。但是現在我需要進一步將頻道2分開。

我試圖用這樣的:

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') 

但是它給了錯誤的結果。是否有任何其他角色,我應該使用的,而不是*(星號)

+0

你嘗試%? – 2014-09-19 09:26:20

+0

我試過了,但是它在解碼語句中不起作用。正如你從答案的下面看到的,它在案件陳述中起作用。但是,謝謝:) – 2014-09-19 09:40:42

回答

1

它可能會更好在這種情況下,...利用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 
+0

我如何在一個組中使用這個case語句? – 2014-09-19 09:46:34

+0

@OleHenrikSkogstrøm你想根據案例的結果進行分組嗎? – 2014-09-19 09:47:38

+0

是的,這是正確的:) – 2014-09-19 09:49:52