-- ROUsages
select 'rousages' sourcetable,vn.versionid, ParentName, FolderName, aa.rofstid, rf.rodbid, rf.dts, rd.Roname, rd.folderpath, ru.rodbid urodbid, count (*) howmany
from vefn_getversionnames() vn
join vefn_getversionitems('') vi on vn.versionid = vi.versionid
join rousages ru on ru.contentid = vi.contentid
join associations aa on aa.versionid = vn.versionid
join rofsts rf on rf.rofstid = aa.rofstid
join rodbs rd on rf.rodbid = rd.rodbid
--where rd.rodbid <> ru.rodbid
group by vn.versionid, ParentName, FolderName, aa.rofstid, rf.rodbid, rf.dts, rd.Roname, rd.folderpath, ru.rodbid
order by rf.dts

-- DROUsages
select 'drousages' sourcetable,vn.versionid, ParentName, FolderName, aa.rofstid, rf.rodbid, rf.dts, rd.Roname, rd.folderpath, dru.rodbid urodbid, count (*) howmany
from vefn_getversionnames() vn
join vefn_getversionitems('') vi on vn.versionid = vi.versionid
join entries ee on ee.ContentID = vi.ContentID
join drousages dru on dru.docid = ee.docid
join associations aa on aa.versionid = vn.versionid
join rofsts rf on rf.rofstid = aa.rofstid
join rodbs rd on rf.rodbid = rd.rodbid
--where rd.rodbid <> dru.rodbid
group by vn.versionid, ParentName, FolderName, aa.rofstid, rf.rodbid, rf.dts, rd.Roname, rd.folderpath, dru.rodbid
order by rf.dts