SQL Flow Field Guide

@@ERROR

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

reads prior-statement state

What changes

Input
error number of the previous statement
Output or change
int (0 on success)
Return type
integer

Syntax at a glance

@@ERROR

Work example

Read the error number from the immediately preceding statement in legacy code.

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

Check your work Prefer TRY...CATCH because another statement can reset @@ERROR before it is read.

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