怎样在视力中实现查询结果向上取整
请问各位高手:
在不在,请教一个问题,我在执行查询视图的时候,想达到一种效果,就是两个字段相除,如遇除不尽的时候向上取整,如遇能够除尽的时候,就是当前整数:
如:9除3=3,如9除以22=5,11除以2=6,11除以3=4 怎么实现,而我用了CEILING()函数,但结果不对,你有什么办法吗?
我的查询语句是这样的:
SELECT dbo.xsjihua.xskehdaim AS 客户, dbo.xsjihua.xskedingdhao AS 订单号,
dbo.xsjihua.xskehxingh AS 客户型号,
qiangli3rd.dbo.SuiGongDan.suigd_biaozhunxinghao AS 标准型号,
dbo.Gbaozhuangxuqiu.gbaozhuangdaima AS 包装代码,
dbo.Gbaozhuangxuqiu.gshuliang AS 数量,
qiangli3rd.dbo.SuiGongDan.suigd_suidanhao AS 生单号,
qiangli3rd.dbo.SuiGongDan.suigd_jitshu AS 投坯数,
CEILING(qiangli3rd.dbo.SuiGongDan.suigd_jitshu / dbo.Gbaozhuangxuqiu.gshuliang)
AS 计领数, dbo.Gbaozhuangxuqiu.gdanwei AS 单位,
qiangli3rd.dbo.SuiGongDan.suigd_chejian AS 车间,
qiangli3rd.dbo.SuiGongDan.suigd_zscjihID AS 生产计划ID,
dbo.Gbaozhuangxuqiu.gbaozhuangID AS 包装ID,
dbo.Gbaozhuangxuqiu.xsfahjihriq AS 计划发日,
dbo.Gbaozhuangxuqiu.zscqianxwanq AS 机加完期,
dbo.Gbaozhuangxuqiu.zscpijwanq AS 坯件完期,
dbo.Gbaozhuangxuqiu.xsxiadanri AS 销下单日,
dbo.Gbaozhuangxuqiu.xsjiaohuqi AS 交货期,
qiangli3rd.dbo.SuiGongDan.suigd_suidanhao1 AS 随单号
FROM qiangli3rd.dbo.SuiGongDan LEFT OUTER JOIN
dbo.Gbaozhuangxuqiu ON
qiangli3rd.dbo.SuiGongDan.suigd_zscjihID = dbo.Gbaozhuangxuqiu.zscjihID LEFT OUTER
JOIN
dbo.xsjihua ON dbo.Gbaozhuangxuqiu.xsjihID = dbo.xsjihua.xsjihID
WHERE (qiangli3rd.dbo.SuiGongDan.suigd_shenhefen = 1)
画横线的地方就是我想让结果向上取整,而查询来的结果让我非常失望,结果却是向下取整,我该怎么实现这一效果,望各位高手多多指教
!
------解决方案--------------------SQL code
CEILING(qiangli3rd.dbo.SuiGongDan.suigd_jitshu*1.0 / dbo.Gbaozhuangxuqiu.gshuliang)
AS 计领数
------解决方案--------------------
CEILING(qiangli3rd.dbo.SuiGongDan.suigd_jitshu / dbo.Gbaozhuangxuqiu.gshuliang /1.0)
AS 计领数
------解决方案--------------------
case when qiangli3rd.dbo.SuiGongDan.suigd_jitshu / dbo.Gbaozhuangxuqiu.gshuliang - floor(qiangli3rd.dbo.SuiGongDan.suigd_jitshu / dbo.Gbaozhuangxuqiu.gshuliang) > 0
then floor(qiangli3rd.dbo.SuiGongDan.suigd_jitshu / dbo.Gbaozhuangxuqiu.gshuliang) + 1
else floor(qiangli3rd.dbo.SuiGongDan.suigd_jitshu / dbo.Gbaozhuangxuqiu.gshuliang)
end
AS 计领数