当前位置: 代码迷 >> Sql Server >> SQL怎么把查询出来的记录保留整数
  详细解决方案

SQL怎么把查询出来的记录保留整数

热度:72   发布时间:2016-04-27 13:41:12.0
SQL如何把查询出来的记录保留整数
我字段类型 是INT类型的 可是这样一查出来 
SQL code
select '数量' as [BNAME],sum(case when day(OQCTime)=1 then Inspection else 0 end) as [1], 。。。。sum(case when day(OQCTime)=31 then Inspection else 0 end) as [31]from TB

Inspection 是INT类型的 可是结果却是这样的 :
BNAME 1 2 ....... 31
数量 0.0000 2.0000

怎么只保留整数啊?

------解决方案--------------------
你用了union all 
把下面的WPP 也用ceiling函数取下整。
------解决方案--------------------
探讨
WPP字段要保留4位小数

------解决方案--------------------
如果你一定要上下的精度不同的话,只能用文本了。
SQL code
select '数量' as [BNAME],ltrim(sum(case when day(OQCTime)=1 then floor(Inspection) else 0 end)) as [1],ltrim(sum(case when day(OQCTime)=31 then floor(Inspection) else 0 end)) as [31]from TB WHERE ....union allselect 'WPP' as [BNAME],ltrim(sum(case when day(OQCTime)=1 then WPP else 0 end)) as [1],...ltrim(sum(case when day(OQCTime)=31 then WPP else 0 end)) as [31]from TB WHERE ....
------解决方案--------------------
SQL code
--原理上就是这样的select ltrim(1) union allselect ltrim(4.5555)/*14.5555*/
  相关解决方案