sqlsql-serversql-server-2008-r2

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.


Solution

  • 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