Welcome to MSDN Blogs Sign in | Join | Help

Jeff Papiez - SQL Server Test Developer

My random thoughts, ideas, comments, and brain dumping ground.
Query for a list of Procs that contain a string

I was browsing the SqlServerCentral.com forums today and came across a post where a user was asking how to write a query to list all the stored procedures that contain a specific string. This might be useful, so I thought I better blog it lest I forget.

CREATE PROCEDURE uspGetProcs (@StringToMatch  AS VARCHAR(256)) AS

    SELECT routine_name
    FROM INFORMATION_SCHEMA.ROUTINES
    WHERE routine_definition 
         
LIKE '%' + @StringToMatch + '%'
    ORDER BY routine_name

The original post can be found here:

http://www.sqlservercentral.com/forums/shwmessage.aspx?messageid=127531

Note: Jon Galloway does point out a great point: Use INFORMATION_SCHEMA rather than the sys* objects as they are subject to change. I edited this post to reflect the more appropriate means of generating the same result. If you want to see the original, click on the link. :)

j.

Posted: Friday, July 23, 2004 8:52 AM by jpapiez
Filed under:

Comments

Jon Galloway said:

I've been taught that it's better to use the information_schema views rather than hitting sysobjects, since sysobjects is subject to change.

select * from information_schema.routines
where routine_definition like '%' + @StringToMatch + '%'
--and specific_name not like 'sp_%'
# July 23, 2004 10:26 AM

Jeff Papiez said:

Thanks for the comment Jon. The post has been updated!
# July 23, 2004 10:48 AM

Anatoly Lubarsky said:

# July 23, 2004 1:27 PM
Anonymous comments are disabled
Page view tracker