-- This query uses the new SQL Server 2005 CROSS APPLY and OUTER APPLY 
-- constructs to apply a table-valued function to the results of a query. 
-- In this example, we use the fFootPrintEq function which returns a list 
-- of SDSS regions that intersect the area specified by the RA, dec and 
-- radius, or NULL if the area is outside the SDSS footprint. 
-- For each point in the input list, in this case the result of a query 
-- on PhotoObj, return "yes" or "no" depending on whether the point is in 
-- the SDSS footprint or not, and any other needed columns.

SELECT top 100 objID, ra, dec, 
	(case when p.type is null then 'NO' else 'YES' end) as found 
FROM PhotoObj AS p 
	OUTER APPLY dbo.fFootprintEq(ra,dec,0.1) 
WHERE (ra between 179.5 and 182.3) and (dec between -1.0 and 1.8) 
