views:

3675

answers:

4

How do I find a stored procedure in a Sybase database given a text string that appears somewhere in the proc? I want to see if any other proc in the db has similar logic to the one I'm looking at, and I think I have a pretty unique search string (literal)

Edit:

I'm using Sybase version 11.2

+2  A: 

In SQL Anywhere and Sybase IQ:

select * from SYS.SYSPROCEDURE where proc_defn like '%whatever%'

I'm not that familiar with ASE, but according to the docs (available from sybooks.sybase.com), it's something like:

select * from syscomments where texttype = 0 and text like '%whatever%'
Graeme Perrow
probably the correct answer, but my db doesn't have that column. I'm running 11.2 on this box (very old indeed) which might be the cause - any other thoughts?
Oskar
Note that "Sybase" is the name of a company, not a product. You are using Sybase Adaptive Server Enterprise (ASE) 11.2.
Graeme Perrow
+2  A: 

Two variations on Graeme's answer (So this also won't work on 11.2):

This lists the name of the sproc too, but will return multiple rows for each sproc if the text appears several times:

select object_name(id),* from syscomments 
   where texttype = 0 and text like '%whatever%'

This lists each sproc just once:

select distinct object_name(id) from syscomments 
   where texttype = 0 and text like '%whatever%'
AdamH
A: 

select * from sysobjects where id in ( select distinct (id) from syscomments where text like '%SearchTerm%') and xtype = 'P'

Tom
A: 

select distinct object_name(syscomments.id) 'SP with LeftOuter Join', syscomments.id from syscomments ,sysobjects where texttype = 0 and text like '%*=%' and syscomments.id=sysobjects.id and sysobjects.type='P'

Nishad Mankar