Solve the Problem of incorrect sp_helptext output format in SQL Server

Source: Internet
Author: User
Use mastergoif object_id ('SP _ SQL ') is not nulldrop proc sp_sqlgo /********************************** **************************************** **************************************** * ************************************ Organizer: chinese style (Roy) Date: 2008.01.01 *************************************** **************************************** **************************************** * *****************************/create pro C [DBO]. [sp_ SQL] (@ objectname sysname) asset nocount on; declare @ print nvarchar (max) ---- @ print use nvarcharif exists (select 1 from syscomments where id = object_id (@ objectname) and encrypted = 1) Begin print n' pairs are encrypted! 'Returnendif coalesce (object_id (@ objectname, n'p'), object_id (@ objectname, n'fn '), object_id (@ objectname, n'if '), object_id (@ objectname, n'tf'), object_id (@ objectname, n'tr'), object_id (@ objectname, n'v ')) is nullbeginprint n' object only records the number of function, stored process, producer, and response! 'Return endprint 'use' + db_name () print 'go 'print 'If object_id (' + quotename (case when charindex (']', @ objectname) = 0 then' ['+ Replace (rtrim (@ objectname ),'. ',']. [') +'] 'else @ objectname end, ''') + ') is not null 'print char (9) + 'drop' + casewhen object_id (@ objectname, N 'P') is not null then' procedure 'when coalesce (object_id (@ objectname, n'fn '), object_id (@ objectname, n'if '), object_id (@ objectname, n'tf') is not null then 'function' when object_id (@ objectname, n'tr ') is not null then 'trigger' else 'view' end + case when charindex (']', @ objectname) = 0 then' ['+ Replace (rtrim (@ objectname ), '. ',']. [') +'] 'else @ objectname endprint 'Go' declare @ t table (COL nvarchar (max) insert @ t select object_definition (object_id (@ objectname )) + char (13) + char (10) While (select max (COL) from @ t)> ''ininselect top 1 @ print = left (COL, charindex (char (13) + char (10), col)-1) from @ tprint @ printupdate @ t set Col = stuff (COL, 1, charindex (char (13) + char (10 ), COL) + 1, '') endprint 'go 'usage: Use test -- specify the number of bytes consumed exec sp_ SQL 'SP _ SQL' -- specify the object
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.