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
Solved

SQL OBJECT_DEFINITION returns stored procedure text for editing

Posted on 2016-07-26
9
49 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 8

Author Comment

by:pzozulka
ID: 41730526
Only results to grid. I need this to work using grid.
0
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

839 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