select dbo.ve_getshortpath(ii.itemid) location, (select count(*) from vefn_ChildItems(ii.ItemID)) children 
from Contents cc
join Items ii on ii.contentid = cc.contentid
where type = 20043
and text in ('DEVICE', 'SETPOINT')
order by (select count(*) from vefn_ChildItems(ii.ItemID)) desc