SQL Flow Field Guide

geography.ShortestLineTo

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

spatial method ShortestLineTo (instance.ShortestLineTo(...))

What changes

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

Syntax at a glance

.ShortestLineTo ( geography_other )

Work example

Use geography.ShortestLineTo to draw the shortest connector between two shapes.

Use matching SRIDs and confirm the output coordinate system. Confirm both values use the same SRID before comparing or combining them.

Check your work The LineString joins the two points, and its length is their shortest distance in metres.

Practice SQL

Open in SQL Flow

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

SELECT a.shape.ShortestLineTo(b.shape).STAsText() AS connecting_line_wkt, a.shape.ShortestLineTo(b.shape).STLength() AS distance_metres FROM (VALUES (geography::Point(47.651, -122.349, 4326))) AS a(shape) CROSS JOIN (VALUES (geography::Point(47.656, -122.343, 4326))) AS b(shape);

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