Format TSQL onto one line

17,583

Solution 1

Using Notepad++

Select the statement that is over multiple lines then on the menu: TextFX>TextFX Edit>Unwrap Text

enter image description here

And for even greater ease you can assign it to a keyboard shortcut using the shortcut mapper (Settings>Shortcut Mapper)

enter image description here

Solution 2

Using Notepad++ (Without any plugin)

After lot's of googling I found that there are no plugins like TextFX and PoorMansTSqlFormatter are available in x64 bit version of notepad++ even not needed.

Notepad++ --> Write Query --> Edit --> Blank Options --> Remove Unnecessary Blank and EOL.

enter image description here

That's it.

Solution 3

You can use the minify comment to remove all the unnecessary space in the Poor Mans TSQL Formatter

[minify]

[/minify]

Solution 4

In SQL Server 2012:

  1. Highlight the selected text and use 'Find and Replace' (ctrl + h)

  2. Check: use Regular Expressions

  3. Find: \n

  4. Replace with: LEAVE BLANK

Solution 5

I like Martin's answer and that is probably the way to go. But I'll point out that you can just use string manipulation to turn carriage returns and line feeds into spaces. This is particularly easy in the later versions of SSMS that enable limted use of regex in the find/replace dialog.

Share:
17,583
KrustyGString
Author by

KrustyGString

Professionally: Stumbling through VB.NET, C#, ASP.NET and SQL Server one error at a time. Personally: Started playing about with C# and XNA. If you like Pong then you're in for a treat. Scratch that, just got a Nexus4 so now I'm messing around with Anrdoid. Ain't nobody go time for that!

Updated on July 27, 2022

Comments

  • KrustyGString
    KrustyGString almost 2 years

    Our company uses an old app which reads TSQL from a .INI file. Due to how the app process the INI file the TSQL has to be all on one line. I use Poor Mans TSQL Formatter to get everything nice and tidy for things like SPs, but am wondering if there's something out there to do the reverse - take nicely formatted TSQL and shove it all onto one line (removing carriage returns , line breaks etc). I'm working in SSMS but also use Notepad++, and will happily use some other editor if it has the functionality.