高分求解(SQL下无法算出小数来啊),在线等!!!

jack_zhong 2004-05-08 03:48:41
我的开发环境是VS2003(VC#)/MS SQL7.0,我写了个过程:
declare @datemaige decimal
declare @worktime decimal
declare @hhcc int

--计算时间差
select @datemaige=ROUND(datediff(minute,@date1,@date2)/60,2)

--select @datemaige

--计算航次
select @hhcc=(select max(hhcc) from jdzy where rtrim(wlcm)=rtrim(@wlcm))+1

--时间位差补加(>0.5的等于1,<0.5的等于0.5)
if len(@datemaige)=8
begin
if right(@datemaige/60,7)>0.5
begin
select @worktime=left(ROUND(@datemaige/60,1),1)+(1-left(@datemaige/60,7))
end
if right(@datemaige/60,7)<0.5
begin
select @worktime=left(ROUND(@datemaige/60,1),1)+(0.5-left(@datemaige/60,7))
end
end
else select @worktime=@datemaige
if len(@datemaige)=9
begin
if right(@datemaige/60,7)>0.5
begin
select @worktime=left(ROUND(@datemaige/60,1),2)+(1-left(@datemaige/60,7))
end
if right(@datemaige/60,7)<0.5
begin
select @worktime=left(ROUND(@datemaige/60,1),2)+(0.5-left(@datemaige/60,7))
end
end
else select @worktime=@datemaige

@date1,@date2是两个时间
select @datemaige=ROUND(datediff(minute,@date1,@date2)/60,2)算不出小数来,
后来单算:select 1655/12 还是算不出小数来,得出了个137,只有整数,我不知道应该系统的事还是SQL语句的事?
...全文
88 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2004-05-08
  • 打赏
  • 举报
回复
SQL的计算就是这样的,如果参与计算的数据都没有小数的话,计算结果就不会有小数

如果参与计算的都是整数的话,计算结果也是整数
zjcxc 元老 2004-05-08
  • 打赏
  • 举报
回复
--主要是你变量没有定义好,因为你没有指定小数位

declare @datemaige decimal(20,2) --改定义,因为你没有定义小数,假设小数位为2位
declare @worktime decimal(20,2) --改定义,因为你没有定义小数,假设小数位为2位
declare @hhcc int
sdhdy 2004-05-08
  • 打赏
  • 举报
回复
这样
select 1655*1.0/12
victorycyz 2004-05-08
  • 打赏
  • 举报
回复

select 1655.0/12

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧