twix, тебе крупно повезло. Как раз отчет пишу.
Код:
select sum(decode(t.doctype,
'WI',
t.quantity,
'WO',
-t.quantity,
'CR',
t.quantity,
'CS',
-t.quantity,
'PD',
t.quantity,
'PE',
-t.quantity)) quant,
t.article article,
nvl(d.locationto, d.locationfrom) loc,
0 as price,
to_date('01.01.2007', 'DD.MM.YYYY') date_price
from smspec t, smdocuments d
where t.doctype = d.doctype
and t.docid = d.id
and d.createdat < &DateEnd
and d.docstate > 2
and d.doctype in ('WI', 'WO', 'CS', 'CR', 'PE', 'PD')
and nvl(d.locationto, d.locationfrom) = &LocId
-- and t.article='80419'
group by t.article, nvl(d.locationto, d.locationfrom)