wood burning stoves
The moose likes Oracle/OAS and the fly likes Converting Negative value to zero Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Converting Negative value to zero" Watch "Converting Negative value to zero" New topic

Converting Negative value to zero

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

I have salary column in my employee table. I have a requirement that while calculating the sum of values in these column, all the negative amounts should be turned to zero.

For example.


Generally when we query as SELECT SUM(SALARY) FROM EMP we get output as 240, but i want to convert -50 and -10 to zero before totalling such that my sum is 100+0+200+0=300

Please let me know if this can be handled through query.

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

Can anyone please help me on this.
Agador Paloi
Ranch Hand

Joined: Jan 24, 2006
Posts: 118
Eshwar -

Your query would look something like this:

Badal Chowdhary
Ranch Hand

Joined: Apr 26, 2011
Posts: 34

One more way is to use case statement. case statements are like if-elseif-else blocks. You could check for any condition and assign a value appropriately. Using decode is also an option for simpler condition checks.

Blog: http://badalchowdhary.wordpress.com/
Twitter: http://twitter.com/badalrocks
I agree. Here's the link: http://aspose.com/file-tools
subject: Converting Negative value to zero
jQuery in Action, 3rd edition