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 > Database Server Software > DB2 > Case in sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-11, 05:01
deeparavi deeparavi is offline
Registered User
 
Join Date: Jul 2010
Posts: 6
Case in sql

I have a case statement in my SQL query like this

Sum(case when amount_d_c= 'd' then -amount else Amount end)As total_amount

My resullts contain numbers with + and - signs.
I want my results to appear again as d if -ve and c if +ve.

Can I add another case statement? If yes how
Please help
Reply With Quote
  #2 (permalink)  
Old 01-13-11, 08:21
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
you want the results of your sum to be either D or C?
then put your case outside of the SUM.
__________________
Dick Brenholtz, Ami in Deutschland
Reply With Quote
  #3 (permalink)  
Old 01-13-11, 22:14
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
do you mean?

Code:
case when Sum(case when amount_d_c= 'd' 
                                   then -amount
                              else Amount
                       end)< 0 
            then 'd'
        else 'c' 
end As total_amount
Dave
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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