我正在使用MSSQL(2012),需要返回一个十进制数字值,以包含相关的货币符号。我已使用CASE
返回货币符号,如下所示:
SELECT (CASE (Currency_ID) WHEN (1) THEN '£' WHEN (2) THEN '$' END) AS Currency_Symbol
然后我想将其与数值相连接,我必须CAST
更正小数位,如下所示:
SELECT CAST(Price AS decimal(10,2)) AS Unit_Price
但是,我似乎无法使用CONCAT
或任何其他方法来执行此操作,而且据我所知,我将无法在同一SELECT
语句中引用'Currency_Symbol'值
有什么想法吗?
答案 0 :(得分:0)
declare @Currency_ID int, @dec decimal(8,2)
set @Currency_ID = 1;
set @dec = 123.45
SELECT (CASE (@Currency_ID) WHEN (1) THEN '£' WHEN (2) THEN '$' END) + cast(@dec as varchar)
已修改..如果您正在使用表,而且Currency_ID和Unit_Price来自表
SELECT (CASE (Currency_ID) WHEN (1) THEN '£' WHEN (2) THEN '$' END) + cast(Unit_Price as varchar) FROM SOMETABLE