January 23, 2007 at 2:00 am
I think this also works.
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%some_text%'
AND ROUTINE_TYPE='PROCEDURE'
January 23, 2007 at 2:30 am
Yep, that's what I was going to do, just not got round to it yet
January 23, 2007 at 6:18 am
That will not work. This returns only the first row of text in syscomments (2000). No idea about 2005.
January 23, 2007 at 7:24 am
Hi,
In your code you use a lot of GROUP BY's --- can you explain why?
Thanks!
January 23, 2007 at 12:43 pm
Sure! Specifically what code are you refering to? The code in the article or the code in the forum (or both)
SQL guy and Houston Magician
January 25, 2007 at 5:40 am
I modified your last query a bit and obtained something that seems to be faster on SQL Server 2000:
SELECT distinct O.Name, O.Type
FROM
(
select
s1.id,
cast(coalesce(s1.text, '') as varchar(8000)) +
cast(coalesce(s2.text, '') as varchar(8000))
as [text]
from syscomments s1 left join syscomments s2
on s2.id = s1.id and s2.colid = s1.colid + 1
) C
INNER JOIN sysobjects O ON C.id = O.Id
WHERE C.TEXT LIKE '%yourSearchString%'
January 25, 2007 at 12:11 pm
Wow! That's much better! Nice work Jesper!
SQL guy and Houston Magician
January 25, 2007 at 12:13 pm
It looks like some of those group bys are unneccessary. Check out Jesper's code for the best 2k approach to date. As far as an explanation goes, This code evolved quite a bit, I never reviewed the code as a whole prior to posting.
In fact, the 2k code was based on the same approach used in the 2k5 code.
SQL guy and Houston Magician
January 7, 2008 at 11:40 am
I recently was examining source code and used a different technique. I believe the following will accomplish the same thing in SQL 2005. I do not know if it works in SQL 2000.
SELECT OBJECT_NAME(object_ID) AS Name, definition
FROM sys.sql_modules
WHERE definition LIKE '%YourSearchString%'
June 12, 2009 at 1:22 pm
I was searching for the 2005 replace for syscomments and found this thread. I see it's fairly old, but figured I'd post the solution I've just worked up this afternoon. It seems to be working out well for me--fast and accurate as far as I tell.
You will need the use of a Numbers/Tally table:
CREATE PROCEDURE admin.pFindStringInCode @StringToFind nvarchar(50) AS SET NOCOUNT ON; SELECT s.[name] AS SchemaName, o.[name] AS ObjectName, CAST(DENSE_RANK() OVER (ORDER BY s.[Name], o.[Name]) AS varchar) + '.' + CAST(ROW_NUMBER() OVER (PARTITION BY s.[Name], o.[Name] ORDER BY s.[Name], o.[Name]) AS varchar) AS Instance, '...'+SUBSTRING(m.definition, CHARINDEX(@StringToFind, m.definition, n.Number), 100)+'...' AS Snippet FROM sys.sql_modules AS m JOIN sys.objects AS o ON o.[object_id] = m.[object_id] JOIN sys.schemas AS s ON o.[schema_id] = s.[schema_id] CROSS JOIN admin.tbl_Numbers AS n WHERE n.Number < LEN(m.definition) AND SUBSTRING(m.definition, n.Number, LEN(@StringToFind)) = @StringToFind AND m.definition LIKE N'%'+ @StringToFind + N'%' SET NOCOUNT OFF; GO
Viewing 10 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply