Declaring and Initializing variables in one statement : SQL Server 2008 T-SQL Enhancements

Leave a comment (0) Go to comments

In SQL Server 2008 onwards, the DECLARE statement has been enhanced to support the declaration and
initialization of variables in one statement.

Now we can initialize values for most data types. The following code example shows how
to declare and initialize a variable.

declare @test_var int =10
print @test_var

In the above example, we have declared variable named @test_var  and also assigned value to that variable in first line. This was the enhancement, this code will not work in SQL Server 2005 and lower versions.

Note :

Long Data type like TEXT, NTEXT, and IMAGE still can not be declared and initialized in one statement.


EOF - Declaring and Initializing variables in one statement : SQL Server 2008 T-SQL Enhancements, SQL Server 2012 , 2008 R2 , 2008 , 2005 , 2000

Leave a Reply

Your email address will not be published. Required fields are marked *


*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.