Kiran Kiran - 2 years ago 122
SQL Question

Append char in SQL select Query

I am new to SQL. I have one banking project, in the in one table have values like this.

Type Amount
----- -------

Credit 5000
Debit 2000

Debit 1000........... so on

Now i need to Fetch these columns.Using Select Statement i can fetch, But i need to append '-' for amount which is Debited( like Debit '-2000'...) and '+' for Credited Amount.

How to append these functions in amount column Using Select Query.
Kindly help me to solve this.

Answer Source

You can also use decode instead of case.

To print the signed value as string

select decode(type,'Debit','-','+')||amount as value from tab;

To keep the value as number but signed

select decode(type,'Debit',-1*amount,amount) as value from tab;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download