Hello All,

Could any well write a query for the following scenario.

Account(table name)

No Name Amount
1 ABCD 2000.00
2 DEFG -2000.00
3 GHIJ 3000.50
4 JKLM 4000.00
5 MNOP 6000.00


O/p Should be in this format

No Name Credit Debit
1 ABCD 2000.00 0
2 DEFG 0 -2000.00
3 GHIJ 3000.50
4 JKLM 0 -4000.00
5 MNOP 6000.00 o


could any one give appropriate query for this

Thnks in Advance

Answer Posted / ajit nayak

select no, name,
case sign(amt) when 1 then amt else 0 end crd,
case sign(amt) when -1 then amt else 0 end debt
from account;

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of index in sql?

561


Does pdo prevent sql injection?

524


What is a table?

569


Is sql port 1433 encrypted?

578


Is oracle sql free?

546






What is varchar data type in sql?

520


What is aggregate function in sql?

539


Does view store data in sql?

540


What is the difference between delete and truncate commands?

517


what is the difference between delete and truncate statement in sql? : Sql dba

556


What are the types of queries in sql?

524


what is the difference between a local and a global temporary table? : Sql dba

558


How is data stored on a disk?

549


What is mdb stand for?

560


What is difference between sql and excel?

519