Search text in stored procedure in SQL Server

I want to search a text from all my database stored procedures . I use the below SQL :

SELECT DISTINCT
       o.name AS Object_Name,
       o.type_desc
  FROM sys.sql_modules m
       INNER JOIN
       sys.objects o
         ON m.object_id = o.object_id
 WHERE m.definition Like '%[ABD]%';

I want to search for [ABD] in all stored procedures including square brackets, but it's not giving the proper result. How can I change my query to achieve this?


Escape the square brackets:

...
WHERE m.definition Like '%[ABD]%' ESCAPE ''

Then the square brackets will be treated as a string literals not as wild cards.


Try this request:

Query

SELECT name
FROM   sys.procedures
WHERE  Object_definition(object_id) LIKE '%strHell%'

Have you tried using some of the third party tools to do the search? There are several available out there that are free and that saved me a ton of time in the past.

Below are two SSMS Addins I used with good success.

ApexSQL Search – Searches both schema and data in databases and has additional features such as dependency tracking and more…

SSMS Tools pack – Has same search functionality as previous one and several other cool features. Not free for SQL Server 2012 but still very affordable.

I know this answer is not 100% related to the questions (which was more specific) but hopefully others will find this useful.

链接地址: http://www.djcxy.com/p/55874.html

上一篇: 使用SQL Server 2008中的PDF文件进行文本搜索

下一篇: 在SQL Server中的存储过程中搜索文本