SQL SERVER – 2008 – Inline Variable Assignment – Declare and Assign Variable

Inline variable assignment is available in SQL Server 2008 or higher version. Beside this is very simple but very useful feature. Many of the programming languages have this feature. But now SQL Server 2008 or higher version has this feature.

Example:

---- SQL Server 2005 or earlier versions 

DECLARE @var1 INT
SET @var1 = 100
SELECT @var1 AS myVar
GO
---- SQL Server 2008 or Higher Version (Inline Variable Assignment) 

DECLARE @var1 INT = 100
SELECT @var1 AS myVar
GO

Hope this help you.