With SQL statement finds all the contents of a database stored procedure contains the (transfer)

Use database
DECLARE @procname VARCHAR (50)
the Create the Table #tmpName (Content VARCHAR (2000))
the Create the Table #tmp (ProcName VARCHAR (2000), Content1 VARCHAR (8000))
- Defines a cursor
DECLARE CURSOR SearchProc the FOR
- query the database the name of the stored procedure, try to remove the system PROC, PROC can find non-system according crdate time field
SELECT name from the sysobjects WHERE type = 'P' and Not name like '% DT_'
the OPEN SearchProc
the FETCH the NEXT the fROM SearchProc 
the INTO @procname

the WHILE @ @FETCH_STATUS> = 0
BEGIN
    Print @procname
    Insert Into #tmpName (Content) Exec sp_helptext @procname
    Insert Into #tmp (ProcName, Content1) ProcName the SELECT @, # tmpName.Content from #tmpName
    - finished on the temporary table filled with empty look
    Truncate table #tmpName
    The NEXT the FROM SearchProc the FETCH
    the INTO @procname
the END
the CLOSE SearchProc
the DEALLOCATE SearchProc
the GO

SELECT ProcName from #tmp WHERE Content1 like 'look content%%' by ProcName Group

SELECT ProcName, Content1 from #tmp WHERE Content1 like 'look content%%'

SELECT ProcName, Content1 from #tmp where procname = 'stored procedure name'
- delete the temporary table
Drop the table #tmpName
Drop the table #tmp

Guess you like

Origin www.cnblogs.com/jijm123/p/11128515.html