日期:2014-05-16 浏览次数:20419 次
Declare @proc_name varchar(100) Declare @fuction_name varchar(100) Declare @seek_text varchar(100) set @fuction_name='tableName' --要查找的字符串 set @seek_text=@fuction_name Declare @sql varchar(8000) Create table #proc_count(proc_name varchar(100),fuction_name varchar(100),[text] varchar(7000)) Create table #proc_text([text] varchar(8000)) Declare Cursor_Function cursor for select quotename(name) from sys.sysobjects where xtype='P' Open Cursor_Function Fetch next from Cursor_Function into @proc_name While @@fetch_status=0 Begin truncate table #proc_text set @sql='' set @sql=@sql+' insert into #proc_text([text]) exec sp_helptext '+''''+@proc_name+''''+' If exists(select 1 from #proc_text where [Text] like '+''''+'%'+@seek_text+'%'+''''+') begin insert into #proc_count(proc_name,fuction_name,[text]) select '+''''+@proc_name+''''+','+''''+@fuction_name+''''+','+'[text] from #proc_text where [Text] like '+''''+'%'+@seek_text+'%'+''''+' end' print @sql exec (@sql) Fetch next from Cursor_Function into @proc_name end close Cursor_Function deallocate Cursor_Function select distinct proc_name,fuction_name from #proc_count order by proc_name drop table #proc_count drop table #proc_text?