Pages

Men

rh

10/18/2013

Local Variables in SQL Server



Variables are declared in the body of a batch or procedure with the DECLARE statement and are assigned values by using either a SET or SELECT statement. 

Example :
DECLARE @VarA INT
DECLARE
 @VarB INT
DECLARE
 @VarTemp INT
SET
 @VarA = 1
SET
 @VarB = 2
SELECT
 @VarA VarA, @VarB VarB
SELECT
 @VarTemp = @VarA, @VarA = @VarB, @VarB = @VarTemp
SELECT
 @VarA VarA, @VarB VarB

No comments :

Post a Comment