Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSMS add comma delimiter - shortcut

Is there a shortcut for adding commas for values for IN clause? e.g. if my query SELECT * FROM Persons WHERE Id IN(.....) and I've copied

356
9874
5975
9771
4166
....

Person's Id values let's say from some Excel file, How can I quickly add ',' comma to the end of each line, so I can paste it IN(....) clause?

like image 282
Levan Avatar asked Jan 23 '14 08:01

Levan


People also ask

What does CTRL R do in SSMS?

The key combination of "CTRL+R" is used to show or hide the query results pane. Sometimes we do not require a query results pane and therefore it can be hidden using the keyboard shortcut keys "CTRL+R". However, there is no direct option to hide this pane.

What does CTRL F5 do in SSMS?

Execute Scripts in SQL Server Management Studio If you want to parse all the scripts without executing them in the current query window, simply press CTRL+F5 or you can select some lines of code to be parsed then press CTRL+F5.


2 Answers

Here's what you need to do:

  1. Put your cursor one space after the 356 (you'll see what you need that extra space in step 2).
  2. Hold down ALT + SHIFT and click the down key for as many numbers as you have. You should see a blue line just to the right of your numbers. This is why you needed the extra space after 356 - so that you can just arrow down the entire list without having to move left or right.

blue line

  1. Release the keys, and press the comma key. A comma should appear in all of the lines.

comma

You can use this method to add quotes or other characters to your SQL queries as well.

like image 55
A Sch Avatar answered Sep 25 '22 01:09

A Sch


I use this in SSMS 2014;

SSMS 2014 replace with delimeter I am not sure if this can be done in previous versions

like image 36
Decoded Avatar answered Sep 26 '22 01:09

Decoded