This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes decode in db2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "decode in db2" Watch "decode in db2" New topic
Author

decode in db2

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have a requirement like
if payment_type = 's' then compensation is weekly_rate * 4
but if weekly_rate is 0 or null then compensation is 0
if payment_type = 'p' return the value in gross_amount column.

Below is the decode function I have used. Would like to know how to do the same using db2 functions.

Decode(payment_type, �s�, (decode(nvl(weekly_rate,0.00),0.00,0.00, weekly_rate*4)) ,�p�,gross_amount)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: decode in db2
 
It's not a secret anymore!