SQL Flow Field Guide

geometry.InstanceOf

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

spatial predicate InstanceOf

What changes

Input
one or two spatial instances
Output or change
bit
Return type
SQL Server return type: bit CLR return type: SqlBoolean

Syntax at a glance

.InstanceOf (geometry_type )

Work example

Use geometry.InstanceOf to check an instance subtype before a subtype-specific operation.

Handle collections separately from simple points, lines, and polygons. Keep the geometry type and SRID in the review.

Check your work MultiPoint is in the GeometryCollection type hierarchy, so InstanceOf returns 1.

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'MULTIPOINT(0 0, 3 4)', 0);
SELECT @shape.InstanceOf('GEOMETRYCOLLECTION') AS is_collection_ancestor, @shape.STGeometryType() AS concrete_type,
       @shape.STSrid AS source_srid,
       @shape.STIsValid() AS source_is_valid;

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