SQL Flow Field Guide

geometry.STNumGeometries

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

spatial method STNumGeometries (instance.STNumGeometries(...))

What changes

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

Syntax at a glance

.STNumGeometries ( )

Work example

Use geometry.STNumGeometries to count members in a spatial collection.

Distinguish collection member count from point count. Keep the geometry type and SRID in the review.

Check your work The GeometryCollection contains 2 members.

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 @shape geometry;
SET @shape = geometry::STGeomFromText(N'GEOMETRYCOLLECTION(POINT(1 1), LINESTRING(0 0, 3 4))', 0);
SELECT @shape.STNumGeometries() AS member_count,
       @shape.STSrid AS source_srid,
       @shape.STIsValid() AS source_is_valid;

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