I posted about sp_findsp previously and decided to revisit it. I didn't write it (see previous post for credit/link) but I did add a bit to it. First, I cleaned it up a bit to make it easier to read, and second, I made it so that it is a system proc so I could access it from any db on my server. I may end up doing some cleanup on it's output, but that's all I had time for for now. So here goes, the new version!
USE master
GO
PRINT 'Checking for the existence of this procedure'
IF (SELECT OBJECT_ID('sp_generate_inserts','P')) IS NOT NULL --means, the procedure already exists
BEGIN
PRINT 'Procedure already exists. So, dropping it'
DROP PROC sp_findsp
END
GO
CREATE PROC sp_findsp @s varchar(255)
AS
BEGIN
DECLARE @msg varchar(255) ,@ul varchar(255)
SELECT @s='%' + @s + '%'
SELECT 'SP Name'=upper(o.name), Seq=colid ,'SP Line'=substring(text,patindex(@s,text)-5, 30)
FROM syscomments c , sysobjects o
WHERE o.id=c.id
and patindex(@s,text) > 0
ORDER BY [name]
SELECT @msg='* Stored procedures containing string "' + @s + '=' + convert(varchar(8),@@rowcount) + ' *'
SELECT @ul=replicate('*',datalength(@msg))
PRINT ' '
PRINT @ul
PRINT @msg
PRINT @ul
END
GO
--Mark procedure as system object
EXEC sys.sp_MS_marksystemobject sp_findsp
GO
PRINT 'Granting EXECUTE permission on sp_findsp to all users'
GRANT EXEC ON sp_findsp TO public
GO