Extracted from a report we use. May be helpful. SQL Code (MS SQL)
select d.ownertable, isNull(l.location, isNull(j.jpnum, isNull(a.assetnum, w.wonum ))) recordnum, d.document, d1.description, d1.urltype, d1.urlname, d.ownerid, d.doctype
from doclinks d
inner join docinfo d1 on d.docinfoid = d1.docinfoid
left outer join ASSET a on d.ownerid = a.assetid and d.ownertable='ASSET'
left outer join WORKORDER w on d.ownerid = w.workorderid and d.ownertable='WORKORDER'
left outer join JOBPLAN j on d.ownerid = j.jobplanid and d.ownertable='JOBPLAN'
left outer join LOCATIONS l on d.ownerid = l.locationsid and d.ownertable='LOCATIONS'
order by d.ownertable, d.ownerid