I am trying to use a SQL Decode statement to Decode (D.code ,2,'Resident',else,'Business') Description, Is there a way to identify everything else in a decode statement?
Asked
Active
Viewed 409 times
0
-
1I'm assuming you're using oracle since DECODE isn't an ansi sql statement as far as I know. Also, I don't really understand the question. – Joe Phillips Aug 13 '13 at 16:06
-
This might help: http://stackoverflow.com/questions/3212059/standard-sql-alternative-to-oracle-decode – Joe Phillips Aug 13 '13 at 16:07
2 Answers
2
yes, there is:
decode ( <condition>, <test expr #1>, <result #1>, ..., <test expr #n>, <result #n>, <fallback result>);
however, in standard sql you would use
case <condition>
when <test expr #1> then <result #1>
...
when <test expr #n> then <result #n>
else <fallback result>
end

collapsar
- 17,010
- 4
- 35
- 61
0
You have the basic syntax correct except you don't use the 'else' in a DECODE function. Inside the parentheses is first the thing to decode, then the code/description pairs, then finally, the optional default (else) value.
Here is a sample of one that I use:
DECODE(status,'A','Approved','D','Declined','I','Counter Offer','Other')
Good luck,
Marvin

MarvinM
- 601
- 6
- 7