I have a table with a single column of geometry type, containing polygons. How do I get the union of all the polygons in the table?
geometry
In SQL Server 2012:
SELECT geometry::UnionAggregate(geomcolumn) FROM YourTable;
In SQL Server 2008/R2:
DECLARE @g = geometry::STGeomFromText('GEOMETRYCOLLECTION EMPTY', YourSRID); SELECT @g = @g.STUnion(geomcolum) FROM YourTable;