Solved

SQL OBJECT_DEFINITION returns stored procedure text for editing

Posted on 2016-07-26
9
34 Views
Last Modified: 2016-07-27
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 ...".
0
Comment
Question by:pzozulka
  • 5
  • 4
9 Comments
 
LVL 24

Expert Comment

by:chaau
ID: 41730489
It works for me. What version of SSMS you have installed?
0
 
LVL 8

Author Comment

by:pzozulka
ID: 41730510
2016. Had 2014 before reinstalled ssms.
0
 
LVL 24

Expert Comment

by:chaau
ID: 41730517
Do you use "results to grid" or "results to text"?
0
 
LVL 8

Author Comment

by:pzozulka
ID: 41730526
Only results to grid. I need this to work using grid.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 24

Expert Comment

by:chaau
ID: 41730547
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
0
 
LVL 8

Author Comment

by:pzozulka
ID: 41730548
When I paste it into the query window it shows up as a single line.
0
 
LVL 24

Expert Comment

by:chaau
ID: 41730556
It must be a bug in ssms2016 then.
0
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 41730560
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
0
 
LVL 8

Author Comment

by:pzozulka
ID: 41731783
That worked. Thanks.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now