O'Reilly logo

Microsoft® SQL Server® 2008 Step by Step by Mike Hotek

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Variables, Parameters, and Return Codes

Variables

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

Definition

@@ERROR

Error code from the last statement executed

@@IDENTITY

Value of the last identity value inserted within the connection

@@ROWCOUNT

The number of rows affected by the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required