If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to convert DECODE to CASE???

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-08, 07:45
raysefo raysefo is offline
Registered User
 
Join Date: Dec 2006
Posts: 17
How to convert DECODE to CASE???

hello,

I have an ORACLE SQL statement like below;

TK.HESAPKODU||'.'||TK.DUZEYKODU1
||DECODE(TK.DUZEYKODU2,NULL,'','.'||TK.DUZEYKODU2)
||DECODE(TK.DUZEYKODU3,NULL,'','.'||TK.DUZEYKODU3)
||DECODE(TK.DUZEYKODU4,NULL,'','.'||TK.DUZEYKODU4)
||DECODE(TK.DUZEYKODU5,NULL,'','.'||TK.DUZEYKODU5)
||DECODE(TK.DUZEYKODU6,NULL,'','.'||TK.DUZEYKODU6) KODU

How can i change it to DB2 CASE???


thanks
Reply With Quote
  #2 (permalink)  
Old 07-14-08, 21:35
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
If changed straighforward to CASE, it would be like this:
CASE WHEN TK.DUZEYKODU2 IS NULL THEN '' ELSE '.'||TK.DUZEYKODU2 END

But, in this case, COALESCE would be simpler.
Like this:
Code:
TK.HESAPKODU||'.'||TK.DUZEYKODU1
||COALESCE('.'||TK.DUZEYKODU2, '') 
||COALESCE('.'||TK.DUZEYKODU3, '') 
||COALESCE('.'||TK.DUZEYKODU4, '') 
||COALESCE('.'||TK.DUZEYKODU5, '') 
||COALESCE('.'||TK.DUZEYKODU6, '') KODU
Reply With Quote
  #3 (permalink)  
Old 07-15-08, 02:24
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
raysefo,
you will have much less problem if you use standard SQL in Oracle too. Decode is Oracle specifics, coalesce is SQL standard. See also this blog post:
http://mennan.kagitkalem.com/NVLCOALESCEDECODE.aspx
Hope it helps,
Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On