TechBubbles Microsoft Technology BLOG

T-SQL TIP in SQL Server 2008

You love this if you write a lot of T-SQL code. This tip I can say as  T-SQL language syntax enhancement. The following are the enhancements in T-SQL

  1. Now We can declare and initialize the variables with single statement.

 

  2. Compound assignment operators are supported.

  3. You can build multiple lines data inline with Row Constructors.

 

Examples:

Variable Assignment

CREATE TABLE EMP(EMPId int, EMPName varchar(150))
GO
-- Declare variable and assign a value in a single statement
DECLARE @EMPId int = 5

 

Compound Assignment Operator

-- Use compound assignment operator to increment ID values
-- to 6, 7, and 8
UPDATE EMP
 SET EMPId += 1

Row Constructors

-- Insert multiple rows in a single statement with 
--IDs 5, 6, and 7
DECLARE @EMPID int = 5;
INSERT INTO EMP VALUES(@EMPId, 'Nick'),
 (@EmpId + 1, 'David'), (@EmpId + 2, 'Major')

Share this post :

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

Add Comment

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud