We help IT Professionals succeed at work.

SQL OBJECT_DEFINITION returns stored procedure text for editing

I've been using OBJECT_DEFINITION for a long time now, and it has been outputting text of stored procedures to the results grid in a nice and readable format (just like sp_helptext).

Yesterday, I upgraded my machine to Windows 10, and had to reinstall SQL Server (management studio). Now all of a sudden OBJECT_DEFINITION is outputting the entire store procedure text in one line, completely unreadable. How do I make it continue to return text to the results grid in a readable format like sp_helptext.

Extra Details
I have a stored procedure I wrote called "sp_prepareSP" which uses OBJECT_DEFINITION to retrieve the stored procedure text. It then appends text before and after the returned text. Things like "IF EXISTS(...) DROP PROCEDURE", and other things like at the end "GRANT EXECUTE ON ...".
Comment
Watch Question

Top Expert 2013

Commented:
It works for me. What version of SSMS you have installed?

Author

Commented:
2016. Had 2014 before reinstalled ssms.
Top Expert 2013

Commented:
Do you use "results to grid" or "results to text"?

Author

Commented:
Only results to grid. I need this to work using grid.
Top Expert 2013

Commented:
I think it still should be fine. What happens when you select it and then paste it to a text editor? The difference between the OBJECT_DEFINITION and sp_helptext is that the former returns a text blob in a single row, and the latter is returns a table with each line in a row:
ssmsI have got ssms2014 - they release new products too fast for me to test them all

Author

Commented:
When I paste it into the query window it shows up as a single line.
Top Expert 2013

Commented:
It must be a bug in ssms2016 then.
Top Expert 2013
Commented:
No, it is not a bug. It is a feature.
Check this article out. They now have a setting "Retain CR/LF on copy or save". Try it:
CRLF

Author

Commented:
That worked. Thanks.