Variables, Parameters, and Return Codes


Variables provide a way to manipulate, store, and pass data within a stored procedure as well as between stored procedures and functions. SQL Server has two types of variables: local and global. A local variable is designated by a single @ symbol whereas a global variable is designated by a double @@ symbol. Additionally, you can create, read, and write local variables whereas you can’t create or write to global variables. Table 12-1 lists some of the more common global variables.

Table 12-1. Global Variables

Global Variable



Error code from the last statement executed


Value of the last identity value inserted within the connection


The number of rows affected by the ...

Get Microsoft® SQL Server® 2008 Step by Step now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.