We have an internal resource used by our developers and support to help identify data issues when we are diagnosing problems in our system. It's used to support a collection of data feeds and they are very customized. What we would like to do is allow one of our users to click the name of a stored procedure and then view the CREATE script of that stored procedure. This is done on an ASP.NET form.
I can get this information by using this statement:
select object_definition(object_id(routine_name))
from information_schema.routines
where routine_name like '%sprocname%'
However, the returned script is unformatted and in a single cell, on a single line. Is there a way for me to format this as if I had right-clicked on the stored procedure in SSMS and select "Script stored procedure as CREATE to"? Because it is all on a single line, if I have commented any portion of the procedure out using two dashes it comments the entire rest of the procedure that follows it.