SQL SERVER – 2008 – Two Convenient Features Inline Assignment – Inline Operations

Sometimes things just go very convenient and we wish that how come it was not available in earlier versions.

Let us see two features here. If it was SQL Server earlier versions we might have to write more lines to achieve what we can achieve in lesser lines. Following small example with only one variable demonstrates this feature.

SQL Server 2005 version:

DECLARE @idx INT
SET
@idx = 0
SET @idx = @idx + 1
SELECT @idx
GO

SQL Server 2008 version:
This version demonstrates two important feature of Inline Assignment and Inline Operations
DECLARE @idx INT = 0
SET @idx+=1
SELECT @idx
GO

Reference : Pinal Dave (http://blog.SQLAuthority.com)

About these ads

8 thoughts on “SQL SERVER – 2008 – Two Convenient Features Inline Assignment – Inline Operations

  1. Good blog, Pinal Dave!

    I think your example labels are backwards… the 2005 version is the new 2008 syntax, isn’t it?

  2. Pingback: SQL Server - DECLARE Multiple Variables in One Statement Journey to SQL Authority with Pinal Dave

  3. Pinal,
    This is a very impressive site. congratulations.

    i appreciate if you can answer this question. the key is code and city. i am on sql server 2005.

    code city test
    132 bangalore test1
    132 chennai test2

    i want the data in one row

    132 bangalore chennai test1 test2

    please help!

  4. Pingback: SQL SERVER – Weekly Series – Memory Lane – #037 | Journey to SQL Authority with Pinal Dave

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s