SQL Flow Field Guide

geometry.STDistance

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

spatial method STDistance (instance.STDistance(...))

What changes

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

Syntax at a glance

.STDistance ( other_geometry )

Work example

Use geometry.STDistance to measure minimum distance between two shapes.

For geometry use coordinate units. For geography verify SRID units with known points. Confirm both values use the same SRID before comparing or combining them.

Check your work Different SRIDs can produce null and units follow the spatial type. Incompatible SRIDs can make a two-instance result null. For this geometry result, verify coordinate units in the planar reference.

Practice SQL

Open in SQL Flow
SELECT geometry::Point(2, 3, 0).STDistance(geometry::Point(5, 7, 0)) AS distance_units;

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