Sql Stuff

Ramblings of all kinds of Sql related tasks - usually related to customer questions, problems, etc. (that's what I do and all)

Katmai - Did you know? Inline variable initialization and Compound assignment

In Sql 2008 (Katmai), a couple of the 'smaller' features that are currently in the latest CTP include inline variable initialization and compound assignment (something you App Dev folks have had for years). So, the following types of code now work in Sql 2008:


  declare @d datetime = getdate(),
    @i int = 1,
    @s varchar(100) = 'test';
 
  -- Show the values...
  select @d, @i, @s
 
  -- Increment i, append to s...
  select @i += 1, @s += 'ing';
 
  -- Show the new values...
  select @i, @s;

These operators also work inline with DML statements and columns...for example, a simple UPDATE statement in a table called 'testTable' with a column called 'testColumn' where you wanted to increment the value of testColumn by 1 could be:

  update testTable set testColumn += 1;
 
Also would work with other columns...if another column called testColumn2 existed:

  update testTable set testColumn += testColumn2;
 

I'll be posting other tidbits in Sql 2008 ongoing...enjoy!

Chad Boyd ~~~ This posting is provided "AS IS" with no warranties, and confers no rights. Use of any included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm.

Published Thursday, July 26, 2007 2:33 AM by boydc7

Comments

 

gduncan411 said:

Nice!

I dig that the T-SQL development process/environment/behavior/language/yada/yada is not being ignored or left to wither, but instead steadily improved. We saw cool T-SQL improvements in SQL2005 and now seeing more in SQL2008...

These things seem like little things, but add up to a great deal.

For a 80% VB/VB.Net & 20% T-SQL developer these changes mean allot.

Thanks for posting this and I'm looking forward to your future tidbits.  

July 26, 2007 12:44 PM
 

Wesley Backelant said:

Very nice.

I can't remember how many times I actually typed this in the previous version of SQL Server :-)

I'm looking forward to your SQL Server 2008 blog posts!

July 27, 2007 1:59 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker