Solved

SQL search thru Stored Procedures

Posted on 2011-03-07
5
286 Views
Last Modified: 2012-05-11
Is there a way to search the text of all stored procedures?  Many times I am about to write a SP and I remember writing similar code, but I do not remember the name of the SP that contains the code.  If I could search all SP's, I could find the code I am about to write.

Is there a 'search" feature for searching thru all stored procedures in SQL 2005?
0
Comment
Question by:dastaub
5 Comments
 
LVL 4

Expert Comment

by:Amgad_Consulting_Co
Comment Utility
0
 
LVL 2

Accepted Solution

by:
grossac earned 500 total points
Comment Utility
This is what I've been using and it works great.


CREATE PROCEDURE [dbo].[SP_UTIL_FindTextInDatabase]
    -- Add the parameters for the stored procedure here
@text nvarchar(1000)

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
declare @newString varchar(205)
Set @newString = '%' + @text + '%'
    -- Insert statements for procedure here
	SELECT
		o.name, 
		SUBSTRING(c.text, CHARINDEX(@text, c.text)-50, 100) as Excerpt,
		c.text
	FROM
		sysObjects o INNER JOIN
		sysComments c ON o.id = c.id
	WHERE
		o.id in (select id from syscomments where text like @newString)
	ORDER by name
END

Open in new window

0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
script out the database into SQL, then search the SQL script and get the sp name from the create statement
0
 

Expert Comment

by:Amit_Kohli
Comment Utility
Right click the database node, click on Tasks, Generate scripts - this will display a wizard to let you choose the objects you want to script, to new file or query window, etc.
Hope this helps.
0
 

Author Closing Comment

by:dastaub
Comment Utility
copied and pasted and it worked.  I changed the SP name to FS so i can type exec FS 'string here' and run.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now