-- Find all objects with proper motions in a given range
--
-- Dave Monet queries 2) and 4)
-- 2) Give me the 5 observed coordinates (RA, Dec, RA motion, Dec motion,
--    parallax) and all available colors for all objects that have
--    proper motions between X and Y arcsec/year.
--    Implicit in this is the hierarchical ordering of the database
--    that goes from "detections" (Ra,Dec,mag,shape,epoch) into
--    "objects" (J2000 Ra+Dec, proper motion, mean color, etc.)
-- 
-- 4) Give me all the objects that have a significant proper motion
--    but do not lie along the stellar locus.
-- 
-- example of query for x=0.1 mas/yr and y=5 mas/yr

SELECT	o.objID, o.ra, o.dec, p.muRa, p.muDec,
	p.plx as parallax, 
	o.grColor, o.riColor, o.izColor, o.zyColor	-- colors from image stack
FROM PPM p JOIN dbo.fGetNearbyObjEq(220.333, 0.45, 90) n -- search on 1.5 degree
	 ON p.objID = n.objID 
	 JOIN Objects o ON o.objID = p.objID  
WHERE
	-- return the total proper motion meeting the required constraint
	p.mu BETWEEN 0.1 AND 5.0
	-- additional color cuts for stellar locus
	-- the following are placeholders, get actual stellar locus
	AND o.grColor BETWEEN -1 AND +1
	AND o.riColor BETWEEN 0.5 AND 2.5
	AND p.plx > -999.99



