SQL Flow Field Guide

SHORTEST_PATH

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

arbitrary-length shortest path search

What changes

Input
node and edge tables in a MATCH pattern with a + or {1,n} quantifier
Output or change
one row per shortest path with graph path aggregates (STRING_AGG, COUNT, LAST_VALUE, ...)

Syntax at a glance

<GRAPH_PATH_AGGREGATE_FUNCTION>(<expression> , <separator>) <order_clause>

Work example

A controlled task needs the behavior documented for SHORTEST_PATH before it is added to a batch.

Read the linked Microsoft syntax and test SHORTEST_PATH with synthetic input in an isolated database. Record its scope, permissions, and error path.

Check your work SHORTEST_PATH. The observed SHORTEST_PATH behavior matches its written purpose and the test has no effect on permanent data or credentials.

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