further to Applying Quotes Across Multiple Lines

Is it possible to create a "surround with" ssms code snippet to turn a list of values across multiple lines into an IN clause, so I could: select the list of values > right click > surround with > select the name of my code snippet in order to turn this:

SELECT * FROM tbl WHERE someValue

into this:

SELECT * FROM tbl WHERE someValue IN (

Yes. You can write your own snippets code in a .snippet file and then import it into SSMS. To import the folder containing the .snippet file:

  1. Open SSMS

  2. Click on Tools ->Code Snippets Manager

  3. Click on Add and select the folder where your custom snippets are written.

I believe this answers a part of your question. You can further follow the below links to get more details.

Adding Custom Snippets: http://www.sqlservercentral.com/articles/SSMS/138994/

About Snippets: https://www.mssqltips.com/sqlservertip/2411/getting-started-with-code-snippets-feature-of-sql-server-2012/

  • Thanks for the answer. My question was really about whether code snippets could be used to add this specific functionality (I couldn't work out whether it is possible from the above links). – AC123 Jun 23 '16 at 8:10

SSMS has useful editing option, column editing. Hold ALT/SHIFT and select column with a mouse (left button pressed), a column selection appears. Type the text. Click anywhere to exit.

  • 3
    And if the values in the list aren't actually all the same length trailing spaces don't matter in string comparisons so selecting the widest column then typing the close quote and comma would work. – Martin Smith Jun 22 '16 at 10:39
  • Thanks Martin, didn't realise the trailing spaces were ignored, however I'm still interested in answering the original question as I believe, in the long term, the code snippet solution would be more efficient / elegant (if it is possible). – AC123 Jun 22 '16 at 10:46
  • Actually just found that the ALT/SHIFT didn't work for me as the trailing spaces were not ignored; they were recognised as a mixture of tabs and spaces and therefore prevented the list of values from matching those in the DB. – AC123 Oct 27 '16 at 8:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.