Rotating Header Image

SQL 2008 Inline Variable Assignment

File this under “New Hotness” with SQL 2008.

SQL 2008 finally gives you the ability to declare and assign your variables in a single line of code.  While this may not be as flashy or huge as some of the other new features in SQL 2008 this is one of the many “small wins” that come with being on SQL Server 2008.

I’ll try and post more “lesser known” new features in SQL 2008 as there are already a tonne articles out there describing the higher profile new features available in SQL 2008.

Code Example for Inline Variable Assignment:
-- The old way of declaring and setting a variable
DECLARE @OldWay INT
SET
@OldWay = 3
SELECT @OldWay 

-- SQL 2008 Inline Variable Assignment
DECLARE @NewWay INT = 3
SELECT @NewWay



Post to Twitter Post to Delicious Post to Digg Post to StumbleUpon

2 Comments

  1. Definitely a nice feature in 2008 that I’ve been wanting for a while! The only annoying part is when you connect to a SQL 2005 server and get syntax errors. :)

  2. SQL 2005? who uses that anymore LOL j/k

Leave a Reply

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.