Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes SUM using two attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SUM using two attributes" Watch "SUM using two attributes" New topic
Author

SUM using two attributes

rahull agarwal
Ranch Hand

Joined: Dec 20, 2010
Posts: 31
Hi,

My table has two columns amount and amountEstimated.

I would like to get a sum of the money using following logic.

If (amount == null) use amountEstimated
Else use amount.

How do I write a SQL for this?

Thanks so much for your help
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That depends on what database you are using. Here is a page which gives examples for a couple of the more common databases.
 
 
subject: SUM using two attributes
 
Similar Threads
How to use Airthmetic operator in Hibernate query
wait() and notify() methods ragarding threads.
Is Composite pattern appropriate ?
jasper - ireport - sum
crystal report using sql server db