Исправил ошибку в последнем блоке проверки спецификации и добавил расшифровку типов документов.
Код:
select distinct sl.name location, t1.id rlnum, obj.typename, t2.id docnum, stf.surname
from (select d.location,
d.doctype,
d.id,
d.createdat,
l1.eventtime crtime,
l2.eventtime uptime
from smdocuments d, smdoclog l1, smdoclog l2
where d.doctype=l1.doctype
and d.id = l1.id
and d.doctype=l2.doctype
and d.id = l2.id
and l1.oldstate = -1
and l2.newstate = 3
and d.doctype = 'RL'
and docstate = 3
and trunc(d.createdat) >= to_date(:MyDate, 'DD.MM.YYYY')) t1,
smdoclog t2,
smstorelocations sl,
smstaff stf, ssobjecttypes obj
where t2.docdate < t1.createdat
and t2.eventtime between t1.crtime and t1.uptime
and t2.newstate in (0, 1, 2, 3)
and t2.doctype in ('PO', 'PE', 'CS', 'CR', 'WO', 'WI')
and (select count(*)
from smspec s1, smspec s2
where s1.doctype=t1.doctype
and s1.docid = t1.id
and s2.doctype=t2.doctype
and s2.docid = t2.id
and s1.article = s2.article) <> 0
and t1.location = sl.id
and t2.employee = stf.id
and t2.doctype = obj.objtype