sql查询的结果
select PayerDate,PaymentAmount from Payments
PaymentAmount - 十进制
Date Amount
12/11/2012 34.31
12/11/2012 95.60
12/11/2012 34.31
可以获得如下查询结果:
Date Amount
12/11/2012 $34.31
12/11/2012 $95.60
12/11/2012 $34.31
我已经尝试了但是找不到太多关于此的信息。
答案 0 :(得分:7)
您可以在投影声明中将其连接起来,
<击> 撞击>
<击>在MySQL中,
SELECT PayerDate, CONCAT('$', PaymentAmount) PaymentAmount
FROM Payments
击> <击> 撞击>
在SQL Server中,
SELECT PayerDate, '$' + CAST(PaymentAmount AS VARCHAR(15)) PaymentAmount
FROM Payments
答案 1 :(得分:2)
尝试此查询
select PayerDate,'$'+convert(varchar,PaymentAmount) as PaymentAmount
from Payments
答案 2 :(得分:1)
您可以将PaymentAmount
转换为字符串,并以美元为前缀:
select PayerDate
, '$' + cast(PaymentAmount as varchar(20)) as PaymentAmount
from Payments
答案 3 :(得分:0)
John Woo sql服务器答案是正确的,但是您可能会收到诸如““ $”不是有效的列名“之类的错误。为了防止出现此错误,请在括号中加上一些括号。
SELECT PayerDate, ('$' + CAST(PaymentAmount AS VARCHAR(15))) AS PaymentAmount
FROM Payments
注意:我只添加了括号。
答案 4 :(得分:-1)
可以尝试以下方法:
SELECT
FORMAT([PayerDate], 'C' 'en-us') AS PayerDate ,
FORMAT([PaymentAmount], 'C', 'en-us') AS 'PaymentAmount'
FROM Payments