select u.*, p.objId, ltrim(str(p.ra,9,5)) as ra, ltrim(str(p.dec,9,5)) as dec, dbo.fPhotoTypeN(p.type) as type from #x x, #upload u, photoTag p where u.up_id = x.up_id and x.objID=p.objID and p.mode=1 order by x.up_id