Results 1 to 3 of 3

Thread: Case in sql

  1. #1
    Join Date
    Jul 2010
    Posts
    6

    Unanswered: 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

  2. #2
    Join Date
    Jun 2007
    Location
    germany
    Posts
    155
    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

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •