Pages

Friday, June 2, 2017

How to remove line breaks in SSMS?

In SQL Server Management Studio (SSMS) there is a command to Delete Blank Lines, though it is not available on a menu, toolbar icon, or keyboard shortcut by default.
If you have to do this regularly, edit your menus, toolbars, or shortcuts to add this command. For example, to add this command to the Edit/Advanced menu:
From the Tools menu, choose Customize:
Tools menu window
In the window that appears, choose the Commands tab, then drop down the Menu Bar list to select Edit | Advanced:
Customize window
Then click Add Command
Add Command selection
Now select the Edit category and scroll the Commands list to select Delete Blank Lines:
Add Command window
Once this is done, Delete Blank Lines will appear in the Edit/Advanced menu. There are other options in the Customize dialogs shown above to position the command in the menu, add a keyboard shortcut, or add an icon for it to a toolbar.


You can do this with find and replace but be warned that if you have string literals with embedded line breaks these will be altered too.
The following finds all instances of consecutive line breaks and replaces them with a single one.
  1. Ctrl + H to open the Find And Replace dialogue
  2. Find What: \n+
  3. Replace With \n
  4. Tick Use -> Regular Expressions
  5. Click Replace/ Replace All
  6. Un-tick Use -> Regular Expressions to avoid confusing results next time you use that dialogue.
enter image description here

No comments:

Post a Comment