- Open a new query window in SQL Server Management Studio.
- Type “xyz”, hit enter twice, and type “xyz” again.
- Now hit CTRL-H to pull up your Find and Replace dialogue.
- Under Find What, type \n\n. Under Replace With, type \n.
- Select Options > Use > Regular Expressions.
- Hit Replace All. Watch your double spaced script magically turn single spaced.
This is the first of many simple uses for regex in SSMS. With just a little poking around online, you can find every reference to a table in a script, regardless of whether it’s bracketed or not ([stats].Tbl and stats.Tbl and stats.[Tbl], etc.). Or, replace all instances of varchar(…) with varchar(500) in your stored procedure. Or, well, whatever you need!
Go on, play around with some regex. Check out Technet’s “Search Text with Regular Expressions” and Simple Talk’s “RegEx-Based Finding and Replacing of Text in SSMS” for more.
*Oh, what alliteration!!