DECODE explanation [message #2692] |
Tue, 06 August 2002 19:31 |
weeang
Messages: 1 Registered: August 2002
|
Junior Member |
|
|
Hi,
I need someone to explain to me exactly what is happening for the following DECODE statement:
"sum(decode(ltrim(a),'01',0,'02',0,'03',0,'04',0,'05',0,'06',0,'07',0,'08',0,to_number(b)*c))"
I actually understand the following DECODE statement as:
"sum(decode(ltrim(a),'08',b*c,0))"
if ltrim(a) = '08' then b*c else 0
Not sure if I got things right or not, but would really appreciate help on this.
Thanks and Brgds, weeang
|
|
|
Re: DECODE explanation [message #2707 is a reply to message #2692] |
Wed, 07 August 2002 09:31 |
MikeT
Messages: 11 Registered: August 2002
|
Junior Member |
|
|
Seems like you've got it right. Basically, it returns 0 for values '01' thru '08'. For everything else it returns "to_number(b)*c".
|
|
|
Re: DECODE explanation [message #2712 is a reply to message #2692] |
Wed, 07 August 2002 11:41 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
Mike's explanation of the intent of the first statement is correct, however your translation is not a match for the logic.
The first statement returns 0 for ltrim(a) values of '01'-'08', and (to_number(b)*c) for all other values.
Your translation return (b*c) for ONLY '08', and 0 for everything else. This is not the same at all.
|
|
|