SELECT db_name() AS dbname, sm.object_id AS obID, o.name, o.type, o.type_desc , definition AS OriginalText , REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(REPLACE(upper(definition), ' INDEX ', '(INDEX') , 'INDEX ', '(INDEX'), ' ', '') , 'CHARINDEX', '') , 'PATINDEX', '') , 'CHARINDEX', '') , 'PATINDEX', '') AS TEXT INTO #tmp1 FROM sys.sql_modules sm LEFT JOIN sys.objects o ON o.object_id = sm.object_id WHERE o.type IN ('AF', 'FN', 'P', 'IF', 'FS', 'FT', 'PC', 'RF', 'TA', 'TF', 'TR', 'V', 'X') SELECT * FROM#tmp1 t WHERE t.text LIKE '%(Index(%' OR t.text LIKE '%(Index=%' ORDER BY t.name --drop table #tmp1