Solved

SQL OBJECT_DEFINITION returns stored procedure text for editing

Posted on 2016-07-26
9
56 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 25

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 25

Expert Comment

by:chaau
ID: 41730517
Do you use "results to grid" or "results to text"?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 8

Author Comment

by:pzozulka
ID: 41730526
Only results to grid. I need this to work using grid.
0
 
LVL 25

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 25

Expert Comment

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

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

Back Up Your Microsoft Windows Server®

Back up 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

734 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