How can you declare and initialize variables in a single line with SQL Server ?

 Posted by Bhakti on 12/4/2009 | Category: Sql Server Interview questions | Views: 13235

With SQL Server 2005, we need to declare and initialize variables individually.
declare @t1 int, 

@t2 varchar(10)
set @t1 = 4
set @t2 = 'Hello!'
print @t1
print @t2

But with SQL 2008, we can do it following way:
declare @t1 int = 4, 

@t2 varchar(10)= 'Hello!'
print @t1
print @t2

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response