我有以下查询给出舍入结果。如何将其修改为
SELECT SUM(Invoice_Details.Amount) AS TotalNet_C FROM Invoice_Details WHERE Invoice_Details.Invoice_Number = ||InvNo||
答案 0 :(得分:0)
要将其格式化为2位数,您可以例如将其转换为货币。
SELECT CAST(SUM(Invoice_Details.Amount) AS money) AS TotalNet_C
FROM Invoice_Details
WHERE Invoice_Details.Invoice_Number = ||InvNo||
更具体地说,您可以使用CONVERT
。
请查看此详细信息:http://msdn.microsoft.com/de-de/library/ms187928.aspx
关于舍入:您想要裁剪数字,而不是围绕它们:
SELECT CAST(CAST(3.456 * 100 AS int) as float)/100
这样做。你的情况呢
SELECT CAST(CAST(CAST(SUM(Invoice_Details.Amount) * 100 AS int) as float)/100 AS money) AS TotalNet_C
FROM Invoice_Details
WHERE Invoice_Details.Invoice_Number = ||InvNo||
答案 1 :(得分:0)
你可以简单地这样做来舍入你的价值
Str(ColumnName, 10, 2)
10-- this is for total length of your value.
2-- this is for how many decimal you want
答案 2 :(得分:0)
declare @Num decimal(6,3)
set @Num = 3.456
select LEFT(round(@Num, 2, 1),4)
OR
select CAST(round(@Num, 2, 1)AS MONEY)
答案 3 :(得分:0)
我认为你应该在sum_function之前转换值,你可以使用数字/小数的参数,就像这样:
select SUM(TRY_CONVERT(decimal(18,2), value) from TestTable ...