title: Returning Polygon Name that contains a point in SQL Server 2014
body: <p>I have a table of 40 polygons, they contain name, id and the geometry. I have a second table of addresses with it's own geometry represented as points. I have aggregated the 40 polygons using <code>geometry::UnionAggregate</code>.</p>
  
  <p>I want to be able to return the id of the polygon for one point in particular from my table of addresses. 
  The following is my code but I get a true value (1) for each of the 40 polygons. I was expecting 39 <code>nulls</code> and '1' for the polygon that actually contains the point. Is this because it is now treating the aggregated polygons as one entity now so therefore they all contain the point? </p>
  
  <p>I am new to spatial queries and may be missing something blindingly obvious but would appreciate some help.</p>
  
  <pre><code>declare @n geometry
  set @n = (select geometry::UnionAggregate(sp_geometry) from Polygons)
  declare @p geometry
  set @p = (select sp_geometry from PointData);
  
  select n.id from Polygons n, pointdata p
  where @n.MakeValid().STWithin(@p) = 1
  </code></pre>