The following script demonstrates how to declare variables and initialized values in single statement in SQL Server 2008.
Method 1
DECLARE @AUTHOR VARCHAR(20) = 'AAMIR HASAN' ,
@SITE VARCHAR(20)= 'WWW.ASPXTUTORIAL.COM'
I have declared two variables named @AUTHOR and @SITE and initialized with values in single statement.
Method 2
DECLARE @AUTHOR VARCHAR(20) ,
@SITE VARCHAR(20)
SET @AUTHOR = 'AAMIR HASAN'
SET @SITE = 'WWW.ASPXTUTORIAL.COM'
Method 3:
DECLARE @DESCRIPTION TEXT(200)
SET @DESCRIPTION = 'WELCOME TO ASPXTUTORIAL.COM'
Msg 2716, Level 16, State 1, Line 2
Column, parameter, or variable #1: Cannot specify a column width on data type text.
Msg 2739, Level 16, State 1, Line 2
The text, ntext, and image data types are invalid for local variables.
Note: Method 1 is not avaible in SQL SERVER 2005 and earlier version of SQL SEVER. Data type text, ntext, or image cannot be declare and assign in single statement.