Site icon Database Tutorials

Assign the data on the same line when defining a variable with “Declare”.

 

In SQL Server 2008, when you define a variable with “Declare”, you can also assign data to that variable in the same row! We could not do this in earlier versions of SQL Server. However, after defining the variable, we were able to assign data to the variable using the “SET” command on another line.

So how do we do this in SQL Server 2008?

For example:

Exit mobile version