SQL version = 2005.
以下查询生成结果2.000000。我希望它只显示2。
如何从结果中删除小数位?
SELECT ROUND(SUM([Total Order (mins)])/60, 0) as [Total Cutting Time (Hours) Saw 50] FROM [IT_REPORTS].[dbo].[cutting_data] WHERE [AssignedCuttingDate] = DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) and [Saw No] = '50'
答案 0 :(得分:0)
round()
的问题是值会发生变化,但不一定是类型。所以,正如你所注意到的那样,你可能会得到一堆尾随的零。
我的建议是转换为小数(或整数):
SELECT CAST(SUM([Total Order (mins)])/60 as DECIMAL(10, 0)) as [Total Cutting Time (Hours) Saw 50]
FROM [IT_REPORTS].[dbo].[cutting_data]
WHERE [AssignedCuttingDate] = DATEADD(day, DATEDIFF(day, 0, getdate()), 0) AND
[Saw No] = '50';
您也可以使用str()
转换为字符串。