SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Search For SPs which contain a specific String.


Search For SPs which contain a specific String.

Author
Message
Prasad Bhogadi
Prasad Bhogadi
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1289 Visits: 450
Comments posted to this topic are about the item Search For SPs which contain a specific String.

Prasad Bhogadi
www.inforaise.com
rwaithaka
rwaithaka
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 102
if OBJECT_ID ('SearchForStringInSPsUpd','P') is not null
drop proc SearchForStringInSPsUpd
Go
create PROCEDURE SearchForStringInSPsUpd @searchfor VARCHAR(100)
AS
DECLARE @spcode varchar(8000),
@spname varchar(100),
@occurance int,
@rowcount int,
@xtype varchar(20)

set nocount on

CREATE TABLE #SPNAMES
(SPNAME varchar(100),SPTYPE varchar(20))


DECLARE GETSPCODE CURSOR FOR

SELECT syscomments.text,sysobjects.name,sysobjects.type

FROM
sysobjects,syscomments

WHERE sysobjects.id = syscomments.id AND (sysobjects.type = 'P' ) AND sysobjects.category=0

union all

SELECT syscomments.text,sysobjects.name,sysobjects.type

FROM
sysobjects,syscomments

WHERE sysobjects.id = syscomments.id AND ( sysobjects.type = 'FN') AND sysobjects.category=0

union all

SELECT syscomments.text,sysobjects.name,sysobjects.type

FROM
sysobjects,syscomments

WHERE sysobjects.id = syscomments.id AND ( sysobjects.type = 'TR') AND sysobjects.category=0



OPEN GETSPCODE
FETCH NEXT FROM GETSPCODE into @spcode,@spname,@xtype
WHILE @@FETCH_STATUS =0
BEGIN
SET @occurance = (SELECT CHARINDEX(@searchfor,@spcode))
IF @occurance > 0
BEGIN
INSERT INTO #SPNAMES(SPNAME,SPTYPE ) VALUES(@spname,@xtype)
END
FETCH NEXT FROM GETSPCODE into @spcode,@spname,@xtype
SET @rowcount=@rowcount-1
END
CLOSE GETSPCODE
DEALLOCATE GETSPCODE


SELECT DISTINCT (LTRIM(RTRIM(SPNAME))) as ObjectName,SPTYPE as ObjectType FROM #SPNAMES

Go

-- I have tweaked the code a bit to search the string in triggers and functions. Enjoy thanks PRASAD.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search