CREATE PROCEDURE [dbo].[spssearchcode]
@text
varchar(250),
@dbname
varchar(64) = 'admin'
AS BEGIN
SET NOCOUNT ON;
if @dbname is null
Begin
--enumerate all
databases.
DECLARE #db CURSOR FOR Select Name from master..sysdatabases
Declare @c_dbname varchar(64)
OPEN #db FETCH #db INTO
@c_dbname
While @@FETCH_STATUS <> -1 --and @MyCount <
500
Begin
execute spssearchcode @text,
@c_dbname
FETCH #db INTO
@c_dbname
End
CLOSE #db DEALLOCATE
#db
End --if @dbname is
null
Else
begin --@dbname is not
null
declare @sql varchar(250)
--create the find like
command
select @sql = 'select ''' + @dbname + ''' as db, o.name,m.definition '
select @sql = @sql + ' from '+@dbname+'.sys.sql_modules m '
select @sql = @sql + ' inner join '+@dbname+'..sysobjects o on m.object_id=o.id'
select @sql = @sql + ' where [definition] like ''%'+@text+'%'''
execute (@sql)
end --@dbname is not
null
END
No comments:
Post a Comment