Sunday, March 8, 2009

SQL SERVER - DECLARE Multiple Variables in One Statement

5 days ago. one of my friend asking me that can be declare multiple variable in one statement.
i found that its possible and thought to post this to my blog.

Method 1: Multiple statements for declaring multiple variables

DECLARE @Var1 INT
DECLARE
@Var2 INT
SET
@Var1 = 1
SET @Var2 = 2
SELECT @Var1 ‘Var1′, @Var2 ‘Var2′

Method 2: Single statements for declaring multiple variables

DECLARE @Var1 INT, @Var2 INT
SET
@Var1 = 1
SET @Var2 = 2
SELECT @Var1 ‘Var1′, @Var2 ‘Var2′
GO


From above example its clear that we can declare multiple variables in one statements.

No comments:

Post a Comment