This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes SUM using two attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SUM using two attributes" Watch "SUM using two attributes" New topic

SUM using two attributes

rahull agarwal
Ranch Hand

Joined: Dec 20, 2010
Posts: 31

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

Joined: Oct 14, 2005
Posts: 19725

That depends on what database you are using. Here is a page which gives examples for a couple of the more common databases.
Have you checked out Aspose?
subject: SUM using two attributes
It's not a secret anymore!