Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Complex Decode Statement in Oracle

Status
Not open for further replies.

nkshah

Programmer
Dec 16, 2009
25
0
0
US


I have one complex Decode statement that i can not able to understand it.

in the parameter it contains--> 1142009 <- as mmqyyyy formate.

Below is the code.

to_char(decode(substr('1142009',4,4),(to_char(sysdate,'yyyy')-2),
decode(substr('1142009',0,2),0,
decode(substr('1142009',3,1),0,12,
5,12,
1,03,
2,06,
3,09,
4,12,substr('1142009',0,2)),substr('1142009',0,2)),
decode(substr('1142009',4,4),(to_char(sysdate,'yyyy')-1),
decode(substr('1142009',0,2),0,
decode(substr('1142009',3,1),0,12,
5,12,
1,03,
2,06,
3,09,
4,12,substr('1142009',0,2)),substr('1142009',0,2)),
decode(substr('1142009',4,4),to_char(sysdate,'yyyy'),
decode(substr('1142009',0,2),0,
decode(substr('1142009',3,1),0,(to_char(r.reporting_date,'mm')-1),
5,to_char(r.reporting_date,'mm'),
1,03,
2,06,
3,09,
4,12,to_char(r.reporting_date,'mm')),substr('1142009',0,2))
,substr('1142009',0,2)))),'00') = pw.month_number <-----table column

Any kind of suggestion welcome.

Thanks.
 
This is really an Oracle question and not a Crystal question. You will probably get a better response if you ask this question in an Oracle forum.

Having said that, here's what I would do:

Find the inner-most Decode from your nested decodes. Figure out what that is doing and then work your way "out" to the outer decode from there.

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top