Converting Query Results to Negative Numbers -- Totalling Results

  • I was given the following example to convert data to negative numbers in a given condition:

    SELECT RecordType, CASE WHEN RecordType = 20 THEN (Quantity_Ord * -1)

    ELSE Quantity_Ord END AS Quantity_Ordered

    FROM TABLENAME

    It works great, but I also need to total the results.  When I tell it to sum the quantity_ordered column, SQL keeps giving me an error that the Sum function requires 1 argument.  I have tried using compute, but the query builder I am using does not allow you to manipulate the code and place it where you need it to go.  It builds the code for you based on the questions you answer.  Is there another way to get the columns to sum that can be placed within the original example above?

     Thanks.

  • select sum (a) from (select sum(amount* -1) as a from TABLENAME where RecordType = 20 union all

    select sum(amount) as a from table1 where RecordType <> 20) a

     

    will give you the sum




    My Blog: http://dineshasanka.spaces.live.com/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply