Use SELECT CASE WHEN ... THEN
http://www.psoug.org/refer
Main Topics
Browse All TopicsTrying to write a query in Discoverer and can't find any sort of If function. I just want to do what in Excel would be:
If([Cost] < 500, 0, [Cost] - 500)
I.e. if the Cost field is less than 500 replace the value with 0, otherwise deduct 500 from the value.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Use SELECT CASE WHEN ... THEN
http://www.psoug.org/refer
Case would be the best. However if you have prior to 9i, you may use decode like:
Select Decode( sign(cost - 500), 1, cost - 500, 0)
from dual;
The sign fn will return 1 if cost > 500 and thus cost - 500 will be returned.
The sign fn will will give 0 or -1 if cost <= 500 and so the default value of 0 will be returned.
Thanks,
Ritesh
Yes, we're on Oracle 8 ... so I've tried this
Select Decode( sign("cost SUM" - 500), 1, "cost SUM" - 500, 0)
from dual;
(The field is actually called "cost SUM")
And I get:
Error in formula, unexpected end of formula
Error: Function SELECT DECODE has not been registered with the EUL
Error: Syntax error: token from dual at position 73
Ritesh_Garg, as far as I know, CASE was introduced with 8i. See http://download-west.oracl
Business Accounts
Answer for Membership
by: nav_kum_vPosted on 2006-10-19 at 07:48:50ID: 17766351
select case when cost < 500 then 0 else cost - 500 end from dual;
Thanks