tags:

views:

495

answers:

2

Hi, i have a situation and couln't figure out for this time.Here's the question.

I have a table for accounting. Transactions are stored in this table.

Table Accounting

Plus Minus Flag

100  0     1
150  0     1
0    230   2
0    200   2

I want to combine these two columns as one column. It would be something like that.

New_Column

100
150
-230
-200

+3  A: 
SELECT Plus - Minus AS New_Column
FROM Accounting
Ed Harper
+1: cool given the completeness of the question
van
Thank you so much. You saved the day.
Semih
A: 

Cool answer from Ed :)

If you need to get the result based on Flag column though, here is the syntax

SELECT  CASE Flag 
            WHEN 1 THEN Plus 
            WHEN 2 THEN -Minus 
            ELSE NULL 
        END AS Total
FROM    Accounting
van
And i tried your solution. It works too. Thanks again.
Semih