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 (https://blog.sqlauthority.com)

SQL Scripts, SQL Utility
Previous Post
SQL SERVER – Find Space Used For Any Particular Table
Next Post
SQL SERVER – 2008 – Introduction to SPARSE Columns

Related Posts

6 Comments. Leave new

  • Nicholas Paldino [.NET/C# MVP]
    July 10, 2008 8:48 pm

    Are you sure you don’t have these mixed up? The 2008 version has MORE lines than the 2005 version.

    Reply
  • Code pasted into wrong sections?

    Reply
  • Good blog, Pinal Dave!

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

    Reply
  • You labels are wrong, top one is 2008, bottom one is 2005.

    Reply
  • 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!

    Reply

Leave a Reply