-- For: Query lot history
--When to use: IF you are tracing bug in production database, this sql can help you to trace the activity of the lot.
select t.activity, h.GROUPHISTKEY,sh.handle, substr(sh.stepid, 1, instr(sh.stepid, '.')-1),
h.lastlocation, h.lotquantity, t.txntimestamp, t.userid, c.briefdescription, c.commentcode , t.*
from fwwiptransaction t, fwwiphistory h, fwwiphistory_n2m hn, fwwipstephistory sh, fwcomment c
where t.wipid='AGZA1F4C0090.01' and h.wiptxn(+) = t.sysid
and h.sysid=hn.fromid(+) and hn.toid=sh.sysid(+) and c.sysid(+)=t.txncomment
order by t.txntimestamp desc