Home > SQL Server 2012 > SQL Server 2012 (DENALI) TSQL – New Feature in SSMS – Surround With

SQL Server 2012 (DENALI) TSQL – New Feature in SSMS – Surround With


I just stumbled on this new exciting feature of SSMS Denali while trying my hands querying on this new environment.

Here is a scenario: You’ve  created a query or a logic with multiple lines of SQL statements. Now you want this to be validated by an IF-ELSE condition or iterate it in a WHILE loop. You will move the cursor to the top and make extra spaces for  inserting IF/WHILE {condition} BEGIN, go to the Bottom and terminate the condition/loop with END statement.

But if you are on Denali you won’t have to do this and type anything. Just a few mouse click would do for you, let’s see how:

1. Select the SQL statement or logic you want to Surround with, then right click on it, select the “Surround With…” option:

Denali SSMS - Surround With 01

2. Now double click on any 3 of your choice, here I selected the “If” condition:

Denali SSMS - Surround With 02

3. The Editor will automatically write the “IF” syntax for you:

Denali SSMS - Surround With 03

4. You just need to add the condition within brackets as per your requirement.

… nice feature introduced by Microsoft.

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: