我正在针对临时表运行2个SQL语句来进行一些计算。第一个运行良好,但在第二个我收到以下错误,我不知道为什么。
Msg 8115,Level 16,State 8,Line 123
算术溢出错误将数字转换为数据类型数字。
也许你可以看到我失踪的东西。以下是我正在使用的陈述和表格。
声明:
update down
Set AMOUNT = case when (up.id is null) then null else
case when(abs(down.SHAMT)<abs(up.SHAMT)
and (down.SHQTY<up.SHQTY or down.SHPU#<up.SHPU#)
and down.GROUPID is not null) then abs(up.SHAMT)-abs(down.SHAMT)
else case when(abs(down.SHAMT)>abs(up.SHAMT)
and (down.SHQTY>up.SHQTY or down.SHPU#>up.SHPU#)
and down.GROUPID is not null) then abs(down.SHAMT)-abs(up.SHAMT) end end end
From #ServiceChange down
join #ServiceChange up
on up.id = down.id-1 and up.SHCUST = down.SHCUST
and up.SHDESC = down.SHDESC
where down.GROUPID in ('SD','SI')
update down
Set AMOUNT= case when (up.id is null) then null else
case when(abs(down.SHAMT)<abs(up.SHAMT)
and down.GROUPID is not null) then abs(up.SHAMT)-abs(down.SHAMT)
else case when(abs(down.SHAMT)>abs(up.SHAMT)
and down.GROUPID is not null) then abs(down.SHAMT)-abs(up.SHAMT) end end end
From #ServiceChange down
join #ServiceChange up
on up.id = down.id-1 and up.SHCUST = down.SHCUST
and up.SHDESC = down.SHDESC
where down.GROUPID in ('PD','PI')
表:
CREATE TABLE #ServiceChange
(
[ID] [int] identity(1,1),
[ORDER] [numeric](8, 0) NOT NULL,
[SHCOMP] [char](2) NOT NULL,
[SHCRTD] [numeric](8, 0) NOT NULL,
[SHCUST] [numeric](7, 0) NOT NULL,
[SHDESC] [char](35) NOT NULL,
[SHTYPE] [char](1) NOT NULL,
[SHAMT] [numeric](9, 2) NOT NULL,
[SHCRTT] [numeric](6, 0) NOT NULL,
[SHQTY] [numeric](5, 0) NOT NULL,
[SHPU#] [numeric](2, 0) NOT NULL,
[CBLNAM] [char](30) NOT NULL,
[CSTRDT] [numeric](8, 0) NOT NULL,
[TBODY] [char](6) NOT NULL,
[GROUPID] [char](2) NULL,
[AMOUNT] [numeric](8, 2) NULL
)
如果需要更多信息,请告知我们。
答案 0 :(得分:1)
也许是因为您想更新价值为[AMOUNT] [numeric](8, 2)
的{{1}}?