Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

append currency symbol to result of sql query

The result of a sql query

select PayerDate,PaymentAmount from Payments

PaymentAmount - decimal

Date        Amount
12/11/2012  34.31
12/11/2012  95.60
12/11/2012  34.31

is that possible to get the result of query as below:

Date        Amount
12/11/2012  $34.31
12/11/2012  $95.60
12/11/2012  $34.31

I have tried but couldn't find much info on this.

like image 692
user1282609 Avatar asked Dec 27 '22 04:12

user1282609


2 Answers

you can concatenate it on your projection statement,

In MySQL,

SELECT PayerDate, CONCAT('$', PaymentAmount) PaymentAmount
FROM Payments

In SQL Server,

SELECT PayerDate, '$' + CAST(PaymentAmount AS VARCHAR(15)) PaymentAmount
FROM   Payments
like image 153
John Woo Avatar answered Dec 28 '22 19:12

John Woo


Try this Query

select PayerDate,'$'+convert(varchar,PaymentAmount) as PaymentAmount
from Payments
like image 40
Prahalad Gaggar Avatar answered Dec 28 '22 17:12

Prahalad Gaggar