TysonLPrice
Programmer
I'm using SQL 2005.
Question #1
Occasionally we are asked to scan our databases for strings. For example recently it was for the User ID which was being expanded to 20 characters. We use a version of sp_Findsp that was copied out. I converted it to search all the databases and it seems to work except the message '* Stored procedures containing string " doesn't print. It does find all the SPs with the string though.
What needs to be added to list the database name along with the stored procedure and text string?
Question #2
Could I loop through the DBs using just sp_Findsp? I tried this and it doesn't work. It just displays the same SPs for each DB.
exec sp_MSforeachdb 'sp_findsp ''UserLUP'''
I read where I need to use '?' to make it loop through as I did in the top one I converted but I don't know how to use it in this case.
Question #1
Occasionally we are asked to scan our databases for strings. For example recently it was for the User ID which was being expanded to 20 characters. We use a version of sp_Findsp that was copied out. I converted it to search all the databases and it seems to work except the message '* Stored procedures containing string " doesn't print. It does find all the SPs with the string though.
Code:
exec sp_MSforeachdb
'declare @s varchar(255)
set @s = ''UserLUP''
DECLARE @msg varchar(255) ,
@ul varchar(255)
select @s=''%'' + @s + ''%''
select ''SP Name''=upper(o.name),
Seq=colid ,
''SP Line''=substring(text,patindex(@s,text)-1, 60)
from ?..syscomments c (nolock) ,
?..sysobjects o (nolock)
where o.id=c.id
and patindex(@s,text) > 0
and o.name in (select Name from ?..sysobjects where xtype = ''P'' )
order by name
SELECT @msg=''* Stored procedures containing string "'' + @s + ''='' +
convert(varchar(8),@@rowcount) + '' *''
SELECT @ul=replicate(''*'',datalength(@msg))
Print '' ''
PRINT @ul
PRINT @msg
Print @ul'
What needs to be added to list the database name along with the stored procedure and text string?
Question #2
Could I loop through the DBs using just sp_Findsp? I tried this and it doesn't work. It just displays the same SPs for each DB.
exec sp_MSforeachdb 'sp_findsp ''UserLUP'''
I read where I need to use '?' to make it loop through as I did in the top one I converted but I don't know how to use it in this case.