SQL Flow Field Guide

geometry.STUnion

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

spatial method STUnion (instance.STUnion(...))

What changes

Input
spatial instance (and arguments)
Output or change
geometry
Return type
SQL Server return type: geometry CLR return type: SqlGeometry

Syntax at a glance

.STUnion ( other_geometry )

Work example

Use geometry.STUnion to combine the point sets of two shapes.

Check matching SRIDs and inspect separate or mixed inputs. Confirm both values use the same SRID before comparing or combining them.

Check your work The union has area 24 square coordinate units and dissolves the shared boundary.

Practice SQL

Open in SQL Flow

Open the SQL for a walkthrough. Run the example in SQL Server to check its result.

-- Planar geometry. SRID 0 coordinates here are synthetic units, not metres.
DECLARE @left geometry;
DECLARE @right geometry;
SET @left = geometry::STGeomFromText(N'POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 0);
SET @right = geometry::STGeomFromText(N'POLYGON((2 0, 6 0, 6 4, 2 4, 2 0))', 0);
SELECT @left.STUnion(@right).STAsText() AS combined_region, @left.STUnion(@right).STArea() AS combined_area_in_square_coordinate_units,
       @left.STSrid AS left_srid,
       @right.STSrid AS right_srid,
       @left.STIsValid() AS left_is_valid,
       @right.STIsValid() AS right_is_valid;

Open Microsoft Learn for full syntax, permissions, and details for your version.