Repeat the same operation on multiple lines in SSMS

Peter Schmitz

Staff member
Suppose the following scenario happens. Finance sends you a list of invoice numbers and asks you to pull data on them. So you fire up SSMS, copy and paste in the list of invoices, and manually start adding start- and end quotes as well as commas around them. First row: Press Home to start at the beginning of the line, add a quote, Press End to go to the end of the line, press quote, press the Down arrow, Press Home, Press comma, press space, press quote, etc.

There's an easier way to do operations on multiple lines, though.

Start by copy/pasting in the invoice numbers:


Position your mouse at the beginning of the second line (the first one to contain the invoice number). Then hold down Alt, and drag your mouse down to the last row of invoices, ensuring you stay in front of the first character of the lines. Note the thin blue line in front of the lines to indicate you marked the lines:


Now press the Quote key to instantly add a quote to the beginning of every line:


Press the End key, hold down ALT again and drag your mouse along the space behind every last character , and then press the quote key again to add a quote at the end of every line:


Skip down to line number 3, and repeat to add a comma and a space in front of every new invoice number.

This trick undoubtedly is going to save me heaps of time, and I hope you'll find it equally useful to cut short some boring repetitive tasks.
Last edited: