Wednesday, November 2, 2011

How to find stored procedure with specific text in the code

I came across a situation where I had to find the list of all such stored procedures defined in a specific database containing at least one cursor in their code. The following query worked for me.

SELECT DISTINCT P.NAME FROM SYSCOMMENTS SC
INNER JOIN SYS.procedures P ON P.OBJECT_ID = SC.ID
AND P.NAME LIKE 'SP%' AND TEXT LIKE '%DECLARE%CURSOR%'

0 comments:

Post a Comment