Pages

Saturday, October 25, 2008

In-line Variable assignment in SQL Server 2008

In SQL Server 2008, there is one feature called In-line variable assignment. Before i get into the details lets lets look at the below code.


>>>In SQL Server 2005
DECLARE @MyEmpNumber INT
SET @MyEmpNumber = 24
SELECT @MyEmpNumber AS EmpNumber
GO
>>>In SQL Server 2008
DECLARE @MyEmpNumber INT = 24
SELECT @MyEmpNumber AS EmpNumber
GO

In 2005 we can't assign the value at the variable declaration, where in 2008 you can do. This will reduce lot of code in T-SQL.

Njoy with this new feature.

No comments: