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 / srinu

Hi Suneel,


SELECT * FROM ACCOUNT;

NO NAME AMOUNT
----- ----- ----------
1 ABCD 2000.00
2 DEFG -2000.00
3 GHIJ 3000.00
4 JKLM -4000.00
5 MNOP 5000.00

SELECT NO,NAME,DECODE(SIGN(AMOUNT),1,TO_CHAR(AMOUNT,'9999.99'),-1,0) CREDIT,
DECODE(SIGN(AMOUNT),-1,TO_CHAR(AMOUNT,'9999.99'),1,0) DEBIT FROM ACCOUNT
/

NO NAME CREDIT DEBIT
------ ----- -------- --------
1 ABCD 2000.00 0
2 DEFG 0 -2000.00
3 GHIJ 3000.00 0
4 JKLM 0 -4000.00
5 MNOP 5000.00 0

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Mention what does plvtab enables you to do when you showthe contents of pl/sql tables?

684


How do you identify a primary key?

642


hi,i plan to put experience on PLSQL ,can anyone suggest me for any institutes in bangalore or how to prepare for interviews

1535


How to assign sql query results to pl sql variables?

521


how to dump a table to a file with 'mysqldump'? : Sql dba

563






What is sql partition?

564


what is an execution plan? When would you use it? How would you view the execution plan? : Sql dba

562


Why partition by is used in sql?

564


what is the difference between char_length and length? : Sql dba

582


What is online transaction processing (oltp)?

607


What is the difference between an inner and outer join?

552


What does pl sql stand for?

665


How many types of relationship are there?

555


How can you view the errors encountered in a trigger?

556


What is substitution variable?

591