sp_FindInProc.txt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. CREATE PROCEDURE sp_FindInProc
  2. @Text1 VARCHAR(200)='',
  3. @Text2 VARCHAR(200)=''
  4. AS
  5. BEGIN
  6. SET NOCOUNT ON;
  7. IF LEN(ISNULL(@Text1,'')) = 0 AND LEN(ISNULL(@Text2,'')) = 0
  8. BEGIN
  9. DECLARE @Info TABLE
  10. (
  11. Info VARCHAR(100)
  12. )
  13. INSERT INTO @Info (Info) VALUES ('sp_FindInProc {Item}')
  14. INSERT INTO @Info (Info) VALUES ('Searches all stored procedures in the current database for text1 and text2')
  15. INSERT INTO @Info (Info) VALUES ('Lists the stored procedure, and a sample of the found text')
  16. INSERT INTO @Info (Info) VALUES ('')
  17. INSERT INTO @Info (Info) VALUES ('Check out other cool tools like')
  18. INSERT INTO @Info (Info) VALUES ('sp_ColumnsInATable')
  19. INSERT INTO @Info (Info) VALUES ('sp_CreateUserDefinedType')
  20. INSERT INTO @Info (Info) VALUES ('sp_DropColumn')
  21. INSERT INTO @Info (Info) VALUES ('sp_Find')
  22. INSERT INTO @Info (Info) VALUES ('sp_FindColumn')
  23. INSERT INTO @Info (Info) VALUES ('sp_FindInAllProcs')
  24. INSERT INTO @Info (Info) VALUES ('sp_List')
  25. INSERT INTO @Info (Info) VALUES ('sp_varinsp')
  26. SELECT Info from @Info
  27. RETURN
  28. END
  29. IF LEN(ISNULL(@Text2,''))=0
  30. BEGIN
  31. SELECT so.name as ProcName,SUBSTRING(sc.text,CHARINDEX(@Text1,sc.text)-20,40) as Sample
  32. FROM sysobjects as so
  33. INNER JOIN syscomments as sc
  34. ON so.id = sc.id
  35. WHERE so.xtype ='P'
  36. AND sc.text like '%'+@Text1+'%'
  37. END ELSE
  38. BEGIN
  39. SELECT so.name as ProcName
  40. ,SUBSTRING(sc.text,CHARINDEX(@Text1,sc.text)-20,40) as Sample1
  41. ,SUBSTRING(sc.text,CHARINDEX(@Text2,sc.text)-20,40) as Sample2
  42. FROM sysobjects as so
  43. INNER JOIN syscomments as sc
  44. ON so.id = sc.id
  45. WHERE so.xtype ='P'
  46. AND sc.text like '%'+@Text1+'%'
  47. AND sc.text like '%'+@Text2+'%'
  48. END
  49. END
  50. GO