SQL Flow Field Guide

SESSION_CONTEXT

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

reads session state

What changes

Input
session key-value store (written by sp_set_session_context)
Output or change
sql_variant value
Return type
sql_variant

Syntax at a glance

SESSION_CONTEXT(N'key')

Work example

Read a key-value item attached to the current SQL session.

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

Check your work Set values through a trusted connection path and do not treat caller-controlled context as authorization.

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