Tuesday, 10 June 2014

How do I find a stored procedure containing a text?

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
    FROM INFORMATION_SCHEMA.ROUTINES
    WHERE ROUTINE_DEFINITION LIKE '%property_doc%'
    AND ROUTINE_TYPE='PROCEDURE'

SELECT OBJECT_NAME(id)
    FROM SYSCOMMENTS
    WHERE [text] LIKE '%property_doc%'
    AND OBJECTPROPERTY(id, 'IsProcedure') = 1
    GROUP BY OBJECT_NAME(id)

SELECT OBJECT_NAME(object_id)
    FROM sys.sql_modules
    WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
    AND definition LIKE '%property_doc%'

3 comments:

  1. SELECT ROUTINE_NAME, ROUTINE_DEFINITION
    FROM INFORMATION_SCHEMA.ROUTINES
    WHERE ROUTINE_DEFINITION LIKE '%property_doc%'
    AND ROUTINE_TYPE='PROCEDURE'

    ReplyDelete
  2. SELECT DISTINCT SCHEMA_NAME(o.schema_id),o.name,[text]
    FROM syscomments AS c
    INNER JOIN sys.objects AS o ON c.id = o.[object_id]
    INNER JOIN sys.schemas AS s ON o.schema_id = s.schema_id
    WHERE text LIKE '%property_doc%'
    ORDER BY SCHEMA_NAME(o.schema_id),o.name

    ReplyDelete
  3. SELECT s.name + '.' + o.name ProcedureName
    , c.text ProcedureSteps
    FROM sys.syscomments c
    INNER JOIN
    sys.objects o
    ON
    c.id = o.object_id
    INNER JOIN
    sys.schemas s
    ON
    o.schema_id = s.schema_id
    WHERE o.type = 'P'
    AND c.text LIKE N'%property_doc%'
    ORDER BY s.name + '.' + o.name
    , c.colid

    ReplyDelete