List Stored Procedures with Contents in SQL Server
I needed to get a list of all stored procedures that accessed a specific column in a table. Some stored procedures generated dynamic SQL statements so the View Dependencies feature was not guaranteed to get me the full list.
This query lets me retrieve the name and body of all stored procedures in a database. Adding the filter to look for the specific column is relatively simple.
SELECT o.Name AS SpName, c.Text AS SpBody FROM syscomments c WITH (NOLOCK) JOIN sysobjects o WITH (NOLOCK) ON c.ID = o.ID AND o.Type = 'P' -- Only stored procedures ORDER BY o.Name
This query is for SQL Server 2005 but should work across all versions.