Stored Procedures Code Search
Suppose you have 1000 stored procedures in the database. Now you have to find something out there in the code. Suppose you want to drop the redundant database table and don't know about whether some procedure uses it. This is a small procedure I build, that would help you to perform such search:
create proc P_TEXT_SEARCH_SPS
(
@p_word varchar(30)
)
as
begin
declare proccurs cursor
for
select C.[text], O.[name]
from
sysobjects O join syscomments C on
C.[id] = O.[id]
where O.xtype = 'p' and O.status > 0
open proccurs
declare @ptext varchar(2000)
declare @pname char(40)
fetch next from proccurs into @ptext, @pname
while @@fetch_status = 0
begin
print @pname + ' = ' +
convert(varchar(5), charindex(@p_word, @ptext, 0))
fetch next from proccurs into @ptext, @pname
end
close proccurs
deallocate proccurs
end
That's it. Happy searching :)
Tuesday, June 22, 2004 2:47 AM