运行查询时出错。 错误是: 将float转换为数据类型numeric的算术溢出错误。
代码:
select g0.docnumber as docnumber
, g0.datum
, g0.crdnr
, datepart(quarter, g0.datum) as quarter
, g0.bkjrcode
, g0.periode
, sum(g0.[Toner Virgin]) as [Toner Virgin]
, sum(g0.[Inkt Virgin]) as [Inkt Virgin]
, sum(g0.[Non Virgin]) as [Non Virgin]
, sum(g0.Mix) as Mix
, sum(g0.Fusers) as Fusers
, sum(g0.[Full]) as [Full]
, sum(g0.Mobiel) as Mobiel
, sum(g0.inkoop) as inkoop
, cast(sum(g0.omzet) as decimal(8, 2)) as omzet
, max(g0.doos) as doos
, max(g0.pallet) as pallet
from (
select g.docnumber
, g.bkjrcode
, g.periode
, g.datum
, a.crdnr
, case
when i.assortment = '130'
then g.aantal
else 0
end as [Toner Virgin]
, case
when i.assortment = '230'
then g.aantal
else 0
end as [Inkt Virgin]
, case
when i.assortment in ('120', '220')
then g.aantal
else 0
end as [Non Virgin]
, case
when i.assortment in ('110', '210')
then g.aantal
else 0
end as Mix
, case
when i.assortment = '140'
then g.aantal
else 0
end as Fusers
, case
when i.assortment in ('100', '200')
then g.aantal
else 0
end as [Full]
, case
when i.assortment between '300'
and '330'
then g.aantal
else 0
end as Mobiel
, case
when i.assortment = '900'
then g.aantal
else 0
end as Afval
, case
when i.assortment between '100'
and '330'
or i.assortment = '900'
then g.bdr_hfl
else 0
end as inkoop
, a.doos
, a.pallet
, isnull(case
when i.assortment between '100'
and '330'
or i.assortment = '900'
then g.aantal * f.verkoop
else 0
end, 0) as omzet
from [110]..gbkmut(nolock) g
inner join [110]..items(nolock) i
on i.itemcode = g.artcode
and i.GLAccountDistribution = g.reknr
left outer join (
select f.artcode
, sum((f.esr_aantal * (f.prijs_n * f.koers - ((f.prijs_n * f.koers / 100) * f.korting)))) as verkoop
from [110]..frhsrg(nolock) f
where f.fakdat >= getdate() - 365
and f.esr_aantal > 0
group by f.artcode
) as f
on f.artcode = g.artcode
inner join (
select a.hid
, c.crdnr
, case
when a.FreeTextField_11 = '00DOOS'
then isnull(a.FreeNumberField_01, 0)
else 0
end + case
when a.FreeTextField_12 = '00DOOS'
then isnull(a.FreeNumberField_02, 0)
else 0
end + case
when a.FreeTextField_13 = '00DOOS'
then isnull(a.FreeNumberField_03, 0)
else 0
end + case
when a.FreeTextField_14 = '00DOOS'
then isnull(a.FreeNumberField_04, 0)
else 0
end as doos
, case
when a.FreeTextField_11 <> '00DOOS'
and left(a.FreeTextField_11, 2) = '00'
then isnull(a.FreeNumberField_01, 0)
else 0
end + case
when a.FreeTextField_12 <> '00DOOS'
and left(a.FreeTextField_12, 2) = '00'
then isnull(a.FreeNumberField_02, 0)
else 0
end + case
when a.FreeTextField_13 <> '00DOOS'
and left(a.FreeTextField_13, 2) = '00'
then isnull(a.FreeNumberField_03, 0)
else 0
end + case
when a.FreeTextField_14 <> '00DOOS'
and left(a.FreeTextField_14, 2) = '00'
then isnull(a.FreeNumberField_04, 0)
else 0
end as pallet
from [synergy]..absences(nolock) a
inner join [synergy]..cicmpy(nolock) c
on c.cmp_wwn = a.CustomerID
where a.type = '1000'
and a.status <> '2'
and c.textfield3 = 'AM'
and (
left(a.FreeTextField_11, 2) = '00'
or left(a.FreeTextField_12, 2) = '00'
or left(a.FreeTextField_13, 2) = '00'
or left(a.FreeTextField_14, 2) = '00'
)
) as a
on cast(a.hid as varchar(max)) = (
select max(g1.docnumber)
from [110]..gbkmut(nolock) g1
where g.bkstnr = g1.bkstnr
and g1.reknr = ' 170200'
)
where g.transtype = 'N'
and g.transsubtype = 'T'
and ltrim(rtrim(g.dagbknr)) = '72'
) as g0
group by g0.docnumber
, g0.datum
, g0.crdnr
, g0.bkjrcode
, g0.periode
我使用了许多子查询。错误是从子查询中触发的,该子查询以&#39;左外连接开始(选择f.artcode&#39;并在包含&#39;的行上结束)为f.artcode = g.artcode&#39;
在此子查询中的行
sum((f.esr_aantal * (f.prijs_n * f.koers - ((f.prijs_n * f.koers / 100) * f.korting)))) as verkoop
导致错误。
子查询中此特定行中的所有字段都是浮点类型。
在这个子查询之外,我正在使用字段“f.verkoop&#39;。
我试图将所有字段从float转换为十进制(10,3),但仍然会收到错误。
有人知道我的代码有什么问题吗?
Eeko