See my SQL-only BLOG at http://blogs.mssqltips.com/blogs/chadboyd Katmai (Sql 2008) - Inline variable initialization and Compound assignment

Katmai (Sql 2008) - Inline variable initialization and Compound assignment

by chad 10/31/2007 11:26:00 AM

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!

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Related posts

Powered by BlogEngine.NET 1.1.3.8
Theme by Mads Kristensen

About the author, Chad


Chad is an Architect, Administrator, and Developer with technologies such as Sql Server (and all related technologies), Windows Server, and Windows Clustering. He currently works with Gratis Internet Inc., an online marketing firm based in Washington, DC (www.gratisinternet.com), and also spends a significant amount of time writing, talking, presenting and blogging about Sql Server in the local DC area and online at mssqltips.com and his personal site, chadhoc.net. In the past, Chad has worked with companies and organizations such as Microsoft Corporation and The American Red Cross, and provided consulting/support services at companies such as Bank of America, HP, Citigroup, Qualcomm, Scottrade, TJX, SunTrust, and Zurich Financial Services. For over 2 years with Microsoft Corporation Chad was responsible for providing onsite and remote support, guidance, and advice with SQL Server products to some of Microsoft’s foremost enterprise customers running the largest, most complex SQL Server installations and configurations in the world. This included all SQL Server products and versions, including SQL Server 7.0, 2000, and 2005, the SQL Server database engine, Reporting Services, SSIS/DTS, Notification Services, and Analysis Services on both 32 and 64 bit systems. Chad's primary responsibilities today include troubleshooting critical server situations, performance tuning and monitoring, disaster recovery planning and execution, architectural guidance for new Sql Server related deployments, and delivering deep technical workshops/presentations/proof-of-concept sessions covering a variety of technologies and functionality.

E-mail me Send mail

Calendar

<<  November 2008  >>
MoTuWeThFrSaSu
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

View posts in large calendar

Pages

    Recent posts

    Recent comments

      Authors

      Categories


        Archive

        Blogroll

        Download OPML file OPML

        Disclaimer

        The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

        © Copyright 2008

        Sign in