I need to search a SQL server 2008 for stored procedures containing where maybe the name of a database field or variable name.
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'%XXXX%'
ORDER BY s.name + '.' + o.name
, c.colid
This query returns the name and the content of any stored procedure where "XXXX" is is referenced within the stored procedure.
This is quit usefull when finding procedures that reference a specific table/view/procedure