/ Published in: SQL

Searches the code for all functions in the current database and returns results containing the function name, the character index where the first match was found, and a portion of the code where the match occurred.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
DECLARE @term VARCHAR(2000) SELECT @term = REPLACE('CROSS JOIN', '%', '\%') SELECT ROUTINE_NAME, ROUTINE_TYPE, PATINDEX('%' + @term + '%', ROUTINE_DEFINITION) AS CharacterIndex, SUBSTRING(ROUTINE_DEFINITION, PATINDEX('%' + @term + '%', ROUTINE_DEFINITION) - 20, 40 + LEN(@term)) AS MatchingCode FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINITION LIKE '%' + @term + '%' AND ROUTINE_TYPE='FUNCTION'
Comments
