如何从SQL 2005查询结果中删除小数位?

时间:2016-11-03 10:12:10

标签: sql sql-server-2005

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'

1 个答案:

答案 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()转换为字符串。