Declare variable and assign initial variable value in a single statement in SQL Server 2008

In SQL Server 2008, you can declare variable and assign initial variable value in a single statement.
Instead of using DECLARE and then SET commands like this:

DECLARE @variable1 varchar(50)
SET @variable1 = 'Test'
SELECT @variable1

...you can declare variable and assign initial variable value in a single statement:

DECLARE @variable1 varchar(50) = 'Test'
SELECT @variable1

The initialization of the variable to that value still happens at execution time.

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">