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
Suneel Reddy

Answer Posted / shailesh

SELECT NO,NAME,DECODE(GREATEST
(AMOUNT,0),0,AMOUNT,0) "DEBIT",DECODE(GREATEST
(AMOUNT,0),0,0,AMOUNT) "CREDIT" FROM ACCOUNT

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you understand by pl/sql cursors?

649


Why are sql stored procedures used?

714


Explain the significance of the & and && operators in pl sql.

643


what are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee (eno int(2),ename varchar(10)) ? : Sql dba

710


What is the use of procedures?

647






can a stored procedure call itself or recursive stored procedure? : Sql dba

657


how to fetch alternate records from a table? : Sql dba

726


What are different types of statements supported by sql?

713


Mention what is the function that is used to transfer a pl/sql table log to a database table?

574


What is foreign key sql?

656


How does left join work in sql?

605


What is the difference between microsoft access and sql server?

610


what is a foreign key ? : Sql dba

696


What is the syntax to add a record to a table?

662


What is cursor status?

867