/* Buscar en todos los procedimientos almacenados y listar el nombre del procedimiento y la fila donde se encuentra la palabra de la búsqueda */ SET NOCOUNT ON DECLARE @ColumnName AS VARCHAR(255) SET @ColumnName = 'DELETE' IF OBJECT_ID('tempdb..#tmpOperacion') IS NOT NULL DROP TABLE #tmpOperacion DECLARE @idSP AS INT DECLARE @tmpTABLE AS TABLE( NombreSP NVARCHAR(255), TextoSP NVARCHAR(MAX)) SELECT @idSP = MIN(OBJECT_ID) FROM sys.procedures WHILE @idSP IS NOT NULL BEGIN DECLARE @nameSP AS VARCHAR(255) SELECT TOP 1 @nameSP = RTRIM(LTRIM(name)) FROM sys.procedures WHERE OBJECT_ID = @idSP IF OBJECT_ID('tempdb..#tmpText') IS NOT NULL DROP TABLE #tmpText CREATE TABLE #tmpText (idRow int identity(1,1), textRow NVARCHAR(MAX)) INSERT INTO #tmpText(textRow) EXEC sp_helptext @nameSP DECLARE @idRow AS INT SELECT @idRow = MIN(idRow) FROM #tmpText WHILE @idRow IS NOT NULL BEGIN DECLARE @textRow AS NVARCHAR(MAX) BEGIN TRY SELECT TOP 1 @textRow = UPPER(textRow) FROM #tmpText WHERE idRow = @idRow IF (SELECT CHARINDEX(@ColumnName, @textRow)) > 0 BEGIN INSERT INTO @tmpTABLE (NombreSP, TextoSP) VALUES (@nameSP, @textRow) BREAK END END TRY BEGIN CATCH --NO REGISTRA EL ERROR END CATCH SELECT @idRow = MIN(idRow) FROM #tmpText WHERE idRow > @idRow END IF OBJECT_ID('tempdb..#tmpText') IS NOT NULL DROP TABLE #tmpText SELECT @idSP = MIN(OBJECT_ID) FROM sys.procedures WHERE OBJECT_ID > @idSP END SELECT NombreSP, TextoSP FROM @tmpTABLE ORDER BY NombreSP SET NOCOUNT OFF
Espero que les sirva de ayuda y que le facilite la vida.