If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > If else?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-09, 04:41
Nebraska_God Nebraska_God is offline
Registered User
 
Join Date: Jun 2006
Posts: 22
Question If else?

I have a table with two count fields. One count is the estimated count and the other is the actual count that is populated later after certain processes run. I want to create a query that totals the actual count but if actual count is 0 I want to use the number in the estimated count field. Any help is appreciated.
Reply With Quote
  #2 (permalink)  
Old 12-11-09, 05:09
Nebraska_God Nebraska_God is offline
Registered User
 
Join Date: Jun 2006
Posts: 22
I got it. I used a case statement.
Reply With Quote
  #3 (permalink)  
Old 12-11-09, 12:22
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,578
You can also use "COALESCE(NULLIF(actual, 0), estimated)".
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On