Что было:
Код:
SELECT s.displayitem displayitem,
s.ARTICLE ARTICLE,
s.NAME NAME,
s.SPECITEM SPECITEM,
round(s.QuantByDoc,-s.Prec) QUANTBYDOC,
s.REASON REASON,
round(s.itemprice,:P_Prec) itemprice,
round(s.quantity,-s.Prec) quantity_fact,
s.MESABBREV MESABBREV,
s.Prec Prec,
round(s.TotalPrice,:P_Prec) TotalPrice_fact,
round(nvl(t.TotalPrice,0),:P_Prec) TotalPrice_doc
FROM supermag.SVSpecNaclRep s, supermag.TTPrintNacl t
WHERE s.DOCID = :P_DOC_ID
AND s.DOCTYPE = :P_DOC_TYPE
and t.doctype(+)=s.doctype
and t.docid(+)=s.docid
and t.specitem(+)=s.specitem
and s.Quantity!=nvl(t.Quantity,0)
ORDER BY &P_SORT,s.displayitem
Что стало:
Код:
SELECT s.displayitem displayitem,
s.ARTICLE ARTICLE,
s.NAME NAME,
s.SPECITEM SPECITEM,
round(s.QuantByDoc,-s.Prec) QUANTBYDOC,
s.REASON REASON,
round(s.itemprice,:P_Prec) itemprice,
round(s.quantity,-s.Prec) quantity_fact,
s.MESABBREV MESABBREV,
s.Prec Prec,
round(s.TotalPrice,:P_Prec) TotalPrice_fact,
round(nvl(t.TotalPrice,0),:P_Prec) TotalPrice_doc,
sm.supplierdoc supplierdoc, -- добавил накладную поставщика
sm.supplierinvoice, -- добавил счет-фактуру поставщика
sm.supplinvoicecreate -- добавил дату создания счет-фактуры
FROM supermag.SVSpecNaclRep s, supermag.TTPrintNacl t, supermag.smwaybillsin sm -- добавил таблицу
WHERE s.DOCID = :P_DOC_ID
AND s.DOCTYPE = :P_DOC_TYPE
and t.doctype(+)=s.doctype
and t.docid(+)=s.docid
and t.specitem(+)=s.specitem
and t.docid = sm.id -- добавил
and t.doctype = sm.doctype -- добавил
and s.Quantity!=nvl(t.Quantity,0)
ORDER BY &P_SORT,s.displayitem
Меня интересуют 2 последних "добавил". Вы ведь это имели ввиду, связать по двум ключам?