Wednesday, October 27, 2010

SP_FIND for SQL SERVER

CREATE PROC dbo.sp_find(@LikeSearchstr VARCHAR(255))
  AS
  /*
  Created by:    Abhishek Joshi
  Created Date:  Oct 27 2010
 
  Usage: To find a object stored proc or views that contain specific sttring.
 
  Example
  Exec dbo.sp_find 'Orders'
 
  */
  BEGIN
 DECLARE @cmd VARCHAR(MAX)

 SET @cmd='
 SELECT Name,OBJECT_DEFINITION(OBJECT_ID) as Text_Definition
 FROM sys.objects
 WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE ''%'+@LikeSearchstr+'%'''

EXEC(@CMD)
  END
 

No comments: