How to Sum up -ve and +ve

  • Hi ,

    I have 2 columns where some rows have -ve numbers and some rows have +ve number...I need to sum up all the -ve and and +ve number and i need to diplay that in 4 columns

    ex

    col1 col2

    -2 4

    4 -3

    2 3

    i need display

    col1-ve col1+ve col2-ve col2+ve

    -2 6 -3 7

    Please help me writing this query

    Thanks

    Raghu

  • Select

    Sum(

    case

    when col10

    then col1

    else 0

    end

    ) as [col1+ve],

    Sum(

    case

    when col20

    then col2

    else 0

    end

    ) as [col2+ve]

    from giventable

    Age2uN

    devloping robust and performant databaseapplications with Microsoft SQL-Server

  • Thank you very much

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

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