Link to home
Create AccountLog in
Avatar of pzozulka
pzozulka

asked on

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 ...".
Avatar of chaau
chaau
Flag of Australia image

It works for me. What version of SSMS you have installed?
Avatar of pzozulka
pzozulka

ASKER

2016. Had 2014 before reinstalled ssms.
Do you use "results to grid" or "results to text"?
Only results to grid. I need this to work using grid.
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:
User generated imageI have got ssms2014 - they release new products too fast for me to test them all
When I paste it into the query window it shows up as a single line.
It must be a bug in ssms2016 then.
ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
That worked. Thanks.