SQL Flow Field Guide

||= (Compound assignment)

Catalog support for SQL Server 2025 (17.x)

compound assignment ||= (Compound assignment)

What changes

Input
target value and an expression
Output or change
the same variable or column
Return type
Assigns the result of the concatenation operator for character strings to the variable. If the variable or expression is a SQL NULL value, then the result of the concatenated expression is NULL. If th

Syntax at a glance

variable ||= expression

Work example

A variable or expression needs the assignment behavior shown by ||= (Compound assignment).

Use one initialized variable and one value. Avoid compound assignment inside queries where row order is not guaranteed.

Check your work ||= (Compound assignment). The assigned value after ||= (Compound assignment) equals the stated expression exactly once.

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