Mirt, Проверял отчетами СМ2000 и своим.
Все сходиться. Огромное спасибо за подсказку.
Код:
select article,
sum (prih) as p,
sum (rash) as r,
sum (k_ost) as ko
from
(
select
article,
decode (no, 1, quantity, 0) as prih,
decode (no, 2, quantity, 0) as rash,
decode (no, 3, quantity, 0) as k_ost
from (
select 1 as no,
article,
quantity
from smspec where doctype in ('WI', 'IW', 'CR')
union all
select 2 as no,
article,
quantity
from smspec where doctype ('WO', 'IW', 'CS')
union all
select 3 as no, article,
sum(q) as quantity
from (
select article, quantity as q from smspec where doctype ('WI', 'IW', 'CR')
union all
select article, -quantity as q from smspec where doctype ('WO', 'IW', 'CS')
)z group by article
) a
) b group by article