Home » RDBMS Server » Server Administration » DECODE STAMNTS
DECODE STAMNTS [message #370510] Sun, 12 December 1999 19:34 Go to next message
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 Go to previous messageGo to next message
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
Decode statmnsts [message #370515 is a reply to message #370513] Tue, 14 December 1999 00:18 Go to previous messageGo to next message
Anish
Messages: 9
Registered: December 1999
Junior Member
Thanks for the help
Re: DECODE STAMNTS [message #372707 is a reply to message #370510] Sun, 04 March 2001 16:32 Go to previous message
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.
Previous Topic: how to select a image from table?
Next Topic: Re: please answer query
Goto Forum:
  


Current Time: Sat Jun 29 00:45:26 CDT 2024