?
Solved

SQL search thru Stored Procedures

Posted on 2011-03-07
5
Medium Priority
?
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:Amgad_Consulting_Co
ID: 35058025
0
 
LVL 2

Accepted Solution

by:
grossac earned 2000 total points
ID: 35058041
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
ID: 35058046
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
ID: 35058349
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
ID: 35058479
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

649 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