• The script searches for patterns in INFORMATION_SCHEMA.ROUTINES

    SET @sqlstm = 'Select Specific_Catalog as Database_Name, Routine_Name as ''Stored Procedure Name'',Routine_Definition

    From '+ @getdbname+'.Information_Schema.Routines

    Where PatIndex('+''''+@SString+''''+', Routine_Definition) > 0'

    The ROUTINE_DEFINITION column here is nvarchar(4000) and only one row is stored per stored procedure/function. Any stored procedure/function that are bigger than nvarchar(4000) will not have the extra contents searched for the pattern.

    It would be better to use sys.sql_modules (checking on the definition column there which is nvarchar(max) and hence will store all the stored procedure/function content)

    SET @sqlstm = '

    Select T1.Specific_Catalog as Database_Name, T1.Routine_Name as ''Stored Procedure Name'',T2.definition

    From '+ @getdbname+'.Information_Schema.Routines T1 INNER JOIN '+ @getdbname+'.sys.sql_modules T2

    ON T1.ROUTINE_NAME = OBJECT_NAME(T2.object_id)

    Where PatIndex('+''''+@SString+''''+', T2.definition) > 0'