Declaring and setting variables in SQL 2008

September 24th, 2008 by Mr.M | No Comments »

Prior to SQL 2008, how would you go about declaring and setting a variable? You would do something like this:

declare @cmd varchar(100)
set @cmd = 'move /Y path/of/source path/of/target'

It takes two lines: one to declare the variable and then one more to set it to whatever you want. In SQL 2008, you can now declare and set the variable in one line:

declare @cmd varchar(100) = 'move /Y path/of/source path/of/target'

Pretty sweet huh?

Leave a Reply

You must be logged in to post a comment.