Monday, January 22, 2007

Free text search stored procedure



Ever wanted search the stored procedures for a specific text, such as a table name or a text tag ?This is impossible in Management Studio, so here follows an example of how to do this..


create procedure hlp_FindTxt
@Instr nvarchar(50)
as
SELECT object_name(sc.id), 'First occurrence of:' + @InStr + ' ...' + substring(sc.text,CHARINDEX(sc.text, @Instr) - 50 ,100) + '...'
FROM syscomments sc inner join sysobjects so on sc.id = so.id
WHERE
sc.text LIKE '%' + @Instr + '%' AND
so.type = 'P' AND
so.name NOT LIKE 'dt_%'
go

0 Comments:

Post a Comment

<< Home