상세 컨텐츠

본문 제목

SP_HELPTEXT2

DataBase/SQL Server

by 탑~! 2016. 7. 19. 13:33

본문

CREATE PROCEDURE SP_HELPTEXT2

(  @objname NVARCHAR(MAX)

)

AS

BEGIN

--DECLARE @objname nvarchar(MAX) = N'sp_Test_sp_helptext';


DECLARE @ObjectText nvarchar(MAX)='';

DECLARE @SyscomText  nvarchar(MAX);

DECLARE @LineLen INT;

DECLARE @LineEnd BIT = 0;

DECLARE @CommentText TABLE(

                             LineId int IDENTITY(1,1)

                           , Text nvarchar(MAX) collate catalog_default

                           );


DECLARE #ms_cur_syscom  CURSOR LOCAL FOR

 SELECT text 

   FROM sys.syscomments

  WHERE id = OBJECT_ID(@objname) and encrypted = 0

  ORDER 

     BY number

      , colid

FOR READ ONLY

OPEN #ms_cur_syscom

FETCH NEXT from #ms_cur_syscom into @SyscomText

WHILE @@fetch_status >= 0

BEGIN

       SET @LineLen = CHARINDEX(CHAR(10),@SyscomText);

       WHILE @LineLen > 0

       BEGIN

              SELECT   @ObjectText += LEFT(@SyscomText,@LineLen)

                     , @SyscomText  = SUBSTRING(@SyscomText, @LineLen+1, 4000)

                     , @LineLen     = CHARINDEX(CHAR(10),@SyscomText)

                     , @LineEnd     = 1;

             

              INSERT INTO @CommentText(Text)

              VALUES (@ObjectText)


              SET @ObjectText = '';

       END


       IF @LineLen = 0

              SET @ObjectText += @SyscomText;

       ELSE

              SELECT  @ObjectText = @SyscomText

                    , @LineLen = 0;


       FETCH NEXT from #ms_cur_syscom into @SyscomText

END


CLOSE  #ms_cur_syscom

DEALLOCATE    #ms_cur_syscom


INSERT INTO @CommentText(Text)

SELECT @ObjectText


SELECT text FROM @CommentText

ORDER BY LineId

END

GO

'DataBase > SQL Server' 카테고리의 다른 글

테이블 칼럼 조회  (0) 2016.08.01
실행계획 보기  (0) 2016.07.25
MS SQL LocalDB 사용하기  (0) 2016.03.23
테이블,컬럼 개체 확장속성 보기 및 등록  (0) 2016.02.23
테이블 리스트  (0) 2016.02.22

관련글 더보기