DECODE STAMNTS [message #370510] |
Sun, 12 December 1999 19:34 |
Anish
Messages: 9 Registered: December 1999
|
Junior Member |
|
|
Consider a table Test with Columns
Pack_id,
GiftBox,
GiftMsg.
How do I write s select statmnt using decode, where, if GiftBox is N & GiftMsg is Y value is 1 or else 0.
Any help will be appreciated.
|
|
|
Re: DECODE STAMNTS [message #370513 is a reply to message #370510] |
Mon, 13 December 1999 07:08 |
Paul
Messages: 164 Registered: April 1999
|
Senior Member |
|
|
Anish,
This should do it (once you substitute your table name).
SELECT Pack_Id,
GiftBox,
GiftMsg,
DECODE(GiftBox,'N',DECODE(GiftMsg,'Y',1,0),0) as VALUE
FROM table;
See the logic, if GiftBox is N, then decode GiftMsg and return the value it returns, otherwise return 0. If GiftMsg (which only gets DECODEd if GiftBox is N) is Y then return 1 otherwise return 0. You can remove the GiftBox and GiftMsg from the list of selected columns, I put them in so you could verify the results more easily but they are not necessary to the operation of the statement.
Hope this helps,
Paul
|
|
|
|
Re: DECODE STAMNTS [message #372707 is a reply to message #370510] |
Sun, 04 March 2001 16:32 |
Isaac
Messages: 5 Registered: March 2001
|
Junior Member |
|
|
how do I decode a letter grade into a value for example here is what I have, and I dont get the correct response
1 select stdid,courseid,decode(substr(grade,1,1),'a ',4,0)
2* from practice.registration
SQL> /
STDID COURSEID DECODE(SUBSTR(GRADE,1,1),'A',4,0)
--------- --------- ---------------------------------
111223333 ISQS6339 0
111223333 BA5382 0
111223333 ISQS6337 0
222334444 ISQS6339 0
222334444 BA5382 0
333221111 BA5382 0
333221111 MKTG5321 0
222334444 BA7000 0
333221111 ISQS6338 0
9 rows selected.
|
|
|