2013-12-17 58 views
-2

我需要從有一個case語句一個選擇,如:PL /從選擇值SQL情況下

select buyer id, 
buyer_add 
buyer_city, 
buyer_state, 
, case 
    when Special_Desc like "%ma%" then "Mail" 
    when Special_Desc like "%pa%" then "phone" 
    else " " 
end as Special_Handling 
     from 
      (select string_func(buyer_id) 
       from advance.pledge p) Special_Desc 
from buyer_info 
    where.. 

換句話說,我需要做的是從一個SELECT語句中產生的Special_desc的情況下,

先謝謝您。

回答

0
Hi this is an example which illustrates how to use case within a select statement. I hope this query resolves your problem. Please let me know for any issues. Thanks 

SELECT sr_no, 
(SELECT 
CASE 
WHEN UPPER(name)=UPPER('Avrajit') THEN 'My_name1' 
WHEN UPPER(name)=UPPER('Shubhojit') THEN 'My_name2' 
END FROM Avrajit 
) AS condition 
FROM avrajit; 
0

你應該是這樣的:

select buyer id, 
     buyer_add 
     buyer_city, 
     buyer_state, 
     case 
     when regexp_like(s.Special_Desc, 'ma*', 'i') then 'Mail' 
     when regexp_like(s.Special_Desc, 'pa*', 'i') then 'Phone' 
     else ' ' 
     end as Special_Handling 
from (select string_func(buyer_id) 
     from advance.pledge p) s, 
    buyer_info 
where.. 

cousr你需要兩個表相關。

+0

謝謝你,我從你的查詢中改變了這個部分:from(select string_func(buyer_id)from advance.pledge p)s,to:from(從advance.pledge p選擇string_func(buyer_id) )special_Desc, 它告訴我缺少右括號和所有parentesis是正確的 – sgg

+0

這是我的實際代碼,但現在它給我'缺少rigth括號,當Sp_Desc喜歡('馬%'),然後'郵件'時Sp_Desc喜歡('PA% ')then'phone'else「」end AS Special_Handling from(string_function(g.buyer_id)from g)AS Sp_Desc – sgg

+0

您不能使用%,這不是正則表達式 – steve

0

我通過使用case語句裏面的函數解決了這個問題。 情況 當STRING_FUNCTION(g.gift_donor_id)等( '%MA%') 然後 'MAIL' 時STRING_FUNCTION(g.gift_donor_id)等( '%MA%') 然後 '電話' 別的 '' 端as Special_H

謝謝大家的寶貴幫助。