• CleverSQLUserID (8/21/2013)


    ScottPletcher (8/14/2013)


    The code uses LIKE to compare the string, so just construct your string accordingly.

    <snip>

    I'll add code to see the actual part(s) of the text that match if you want.</snip>

    Yes, please!

    I don't even know where to begin for that...

    Here's an example; naturally change the "backup" bytes and the total bytes listed to whatever you prefer:

    IF OBJECT_ID('tempdb..#search_strings') IS NOT NULL

    DROP TABLE #search_strings

    CREATE TABLE #search_strings (

    search_id int IDENTITY(1, 1) NOT NULL,

    search_string nvarchar(40) NOT NULL

    )

    INSERT INTO #search_strings

    SELECT 'linked_server_name1'

    --UNION ALL SELECT 'linked_server_name2'

    --UNION ALL ...

    SELECT

    OBJECT_NAME(object_id) AS Object_Name,

    search_string,

    --list 100 bytes of the definition, starting 40 bytes before the string itself was found

    (SELECT SUBSTRING(definition, derived.string_location - 40, LEN(search_string) + 100) FROM sys.sql_modules WHERE object_id = derived.object_id) AS Object_Text

    FROM (

    SELECT

    sm.object_id,

    ss.search_string,

    PATINDEX('%' + ss.search_string + '%', sm.definition) AS string_location

    FROM sys.sql_modules sm

    CROSS JOIN #search_strings AS ss

    WHERE

    CAST(OBJECTPROPERTYEX(sm.object_id, 'IsProcedure') AS int) = 1 AND

    sm.definition LIKE '%' + ss.search_string + '%'

    ) AS derived

    ORDER BY

    Object_Name

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.