1

I am having data like below which included mince and plus values.

AccCode   Value 
------------------------
1-2110    2000
1-3110    -100
2-4110    -400
4-5100    1000

I need below out put without creating a temporary SQL table

AccCode     Debit   Credit
 1-2110     2000        0
 1-3110        0     -100
 2-4110        0     -400
 4-5100     1000        0

Can anybody help me?

Sudu
  • 51
  • 1
  • 2
  • 9
  • I think [this](http://stackoverflow.com/questions/63447/how-do-you-perform-an-if-then-in-an-sql-select) might have an answer... – ikh Dec 02 '14 at 12:15
  • Welcome to StackOverflow: if you post code, XML or data samples, **please** highlight those lines in the text editor and click on the "code samples" button ( `{ }` ) on the editor toolbar to nicely format and syntax highlight it! Then you don't need any of those messy `

    ..

    `, `
    ` or ` ` tags, either!!
    – marc_s Dec 02 '14 at 12:33

1 Answers1

0
select acccode, 
       case
         when value >= 0 then value 
         else 0
       end as debit,
       case 
         when value < 0 then value 
         else 0
       end as credit
from the_table