select ii.ItemID, dbo.ve_GetShortPath(pr.itemid) location, vn.*  from items ii 
join vefn_GetVersionItems('') vi on vi.ItemID = ii.ItemID
join vefn_GetVersionNames() vn on vn.VersionID = vi.VersionID
join contents cc on cc.ContentID = ii.contentid 
join parts pp on pp.ContentID = cc.ContentID and pp.FromType = 5
join items ir on ir.ItemID = pp.ItemID
join parts pr on pr.ContentID = ir.ContentID and pr.FromType = 6
left join parts ps on ps.ContentID = cc.ContentID and ps.FromType = 6
where ii.PreviousID is not null and ii.itemid not in (select PreviousID from items where PreviousID is not null)  
and cc.type in (20002, 20003, 20009, 20018, 20040, 20041) and ps.ContentID is null
and dbo.ve_GetShortPath(pr.itemid) not like '%purpose%'