Skip to content

Instantly share code, notes, and snippets.

@ewoo
Created October 8, 2015 18:10
Show Gist options
  • Save ewoo/350f2a4abd0c52c6ab0a to your computer and use it in GitHub Desktop.
Save ewoo/350f2a4abd0c52c6ab0a to your computer and use it in GitHub Desktop.
Search for a specific string inside a SQL stored procedure object.
DECLARE @find VARCHAR(1000)
SET @find = '%search string%'
SELECT
sp.name,
ISNULL(smsp.definition, ssmsp.definition) AS [Definition]
FROM
sys.all_objects AS sp
LEFT OUTER JOIN sys.sql_modules AS smsp ON smsp.object_id = sp.object_id
LEFT OUTER JOIN sys.system_sql_modules AS ssmsp ON ssmsp.object_id = sp.object_id
WHERE
(sp.type = N'P' OR sp.type = N'RF' OR sp.type='PC')
AND ISNULL(smsp.definition, ssmsp.definition) LIKE '%' + @find + '%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment