title: SQL Geometry find all points in a radius
body: <p>I am fluent in SQL but new to using the SQL Geometry features. I have what is probably a very basic problem to solve, but I haven't found any good resources online that explain how to use geometry objects. (Technet is a lousy way to learn new things...)</p>
  <p>I have a collection of 2d points on a Cartesian plane, and I am trying to find all points that are within a collection of radii.</p>
  <p>I created and populated a table using syntax like:</p>
  <p>Update [Things] set [Location] = geometry::Point(@X, @Y, 0)</p>
  <p>(@X,@Y are just the x and y values, 0 is an arbitrary number shared by all objects that allows set filtering if I understand correctly)</p>
  <p>Here is where I go off the rails...Do I try to construct some sort of polygon collection and query using that, or is there some simple way of checking for intersection of multiple radii without building a bunch of circular polygons?</p>
  <p>Addendum: If nobody has the answer to the multiple radii question, what is the single radius solution?</p>
  <p>UPDATE</p>
  <p>Here are some examples I have worked up, using an imaginary star database where stars are stored on a x-y grid as points:</p>
  <p>Selects all points in a box:</p>
  <pre><code>DECLARE @polygon geometry = geometry::STGeomFromText('POLYGON((' 
  + CAST(@MinX AS VARCHAR(10)) + ' '  + CAST(@MinY AS VARCHAR(10)) + ',' 
  + CAST(@MaxX AS VARCHAR(10)) + ' '  + CAST(@MinY AS VARCHAR(10)) + ', ' 
  + CAST(@MaxX AS VARCHAR(10)) + ' '  + CAST(@MaxY AS VARCHAR(10)) + ',' 
  + CAST(@MinX AS VARCHAR(10)) + ' '  + CAST(@MaxY AS VARCHAR(10)) + ',' 
  + CAST(@MinX AS VARCHAR(10)) + ' '  + CAST(@MinY AS VARCHAR(10)) + '))', 0);
  
  SELECT  [Star].[Name]           AS [StarName],
          [Star].[StarTypeId]     AS [StarTypeId],        
  FROM    [Star]
  WHERE   @polygon.STContains([Star].[Location]) = 1
  </code></pre>
  <p>using this as a pattern, you can do all sorts of interesting things, such as
  defining multiple polygons:</p>
  <pre><code>WHERE   @polygon1.STContains([Star].[Location]) = 1
  OR @polygon2.STContains([Star].[Location]) = 1
  OR @polygon3.STContains([Star].[Location]) = 1
  </code></pre>
  <p>Or checking distance:</p>
  <pre><code>WHERE [Star].[Location].STDistance(@polygon1) &lt; @SomeDistance 
  </code></pre>
  <p>Sample insert statement</p>
  <pre><code>INSERT [Star]
  (
      [Name],
      [StarTypeId],
      [Location],
  )
  VALUES
  (
      @Name,
      @StarTypeId,
      GEOMETRY::Point(@LocationX, @LocationY, 0),
  )
  </code></pre>