SQL Flow Field Guide

geography.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_geography )

Work example

Use geography.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 geography result, verify the instance SRID before interpreting its coordinates.

Practice SQL

Open in SQL Flow
SELECT geography::Point(0.01, 0.02, 4326).STDistance(geography::Point(0.02, 0.03, 4326)) AS distance_metres;

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