22,209
社区成员
发帖
与我相关
我的任务
分享
select cast(0.032 as decimal(18,3)) a into #a
select cast(0 as decimal(18,2)) b into #b
-- > sum相当于累加,最终的精度是(38,2)
select sum(b) c into #c from #b
select name, xprec, xscale from tempdb..syscolumns where id = object_id('tempdb.dbo.#c')
/*
name xprec xscale
-------- ----- ------
c 38 2*/
/*
a(18,3) + c(38,2)
为了保证整数部分的精度,所以最终精度取(38,2)
*/
drop table #a,#b,#c
那你就用
select cast(0.032 as decimal(18,3)) a into #a
select cast(0 as decimal(18,2)) b into #b
update #a set a=isnull(a,0)+isnull((select b from #b),0)