Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 499 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search text in stored procedure in SQL Server

#1
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?
Reply

#2
I usually run the following to achieve that:

select distinct object_name(id)
from syscomments
where text like '%[ABD]%'
order by object_name(id)
Reply

#3
Using [CHARINDEX](

[To see links please register here]

):

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 CHARINDEX('[ABD]',m.definition) >0 ;

Using [PATINDEX](

[To see links please register here]

):

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 PATINDEX('[[]ABD]',m.definition) >0 ;

Using this double `[[]ABD]` is similar to escaping :

WHERE m.definition LIKE '%[[]ABD]%'
Reply

#4
Also you can use:


SELECT OBJECT_NAME(id)
FROM syscomments
WHERE [text] LIKE '%flags.%'
AND OBJECTPROPERTY(id, 'IsProcedure') = 1
GROUP BY OBJECT_NAME(id)

Thats include comments
Reply

#5
select top 10 * from
sys.procedures
where object_definition(object_id) like '%\[ABD\]%'
Reply

#6
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][1] – Searches both schema and data in databases and has additional features such as dependency tracking and more…

[SSMS Tools pack][2] – 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.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#7
You can also use this one:

SELECT *
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION like '%Search_String%'
Reply

#8
[Redgate's SQL Search][1] is a great tool for doing this, it's a free plugin for SSMS.




[1]:

[To see links please register here]

Reply

#9
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 '%[String]%';
Reply

#10
You can also use

CREATE PROCEDURE [Search](
@Filter nvarchar(max)
)
AS
BEGIN

SELECT name
FROM procedures
WHERE definition LIKE '%'+@Filter+'%'

END

and then run

exec [Search] 'text'
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through