SQL Flow Field Guide

$PARTITION

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

partition routing

What changes

Input
a partition function and a value
Output or change
partition number
Return type
int

Syntax at a glance

[ database_name. ] $PARTITION.partition_function_name(expression)

Work example

Find the partition number selected by a partition function for one value.

Read state in the intended scope and immediately after the statement it describes. Treat host values as untrusted.

Check your work Check the function and boundary direction because the result is not a row count.

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