Created
October 9, 2019 20:14
-
-
Save maxkoshevoi/2d12c37a89d71cadcd1de3fbcda76d06 to your computer and use it in GitHub Desktop.
Search for text inside every stored procedure of MSSQL database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET NOCOUNT ON | |
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED | |
select distinct | |
so.[xtype], | |
so.[id], | |
so.[name], | |
po.[name] | |
from sysobjects so | |
left join sysobjects po | |
on po.[id] = so.[parent_obj] | |
join (select | |
id = sc1.id, | |
col1 = sc1.colid, | |
col2 = sc2.colid, | |
text = case when sc1.colid = sc2.colid | |
then sc1.text | |
else substring(sc1.text, 2001, 2000) + substring(sc2.text, 1, 2000) | |
end | |
from syscomments sc1 | |
join syscomments sc2 | |
on sc1.id = sc2.id | |
and sc2.colid - sc1.colid in (0,1) | |
) sc | |
on sc.[id] = so.[id] | |
where charindex( | |
----------------------------------------- | |
'TEXT_TO_SEARCH_FOR' | |
----------------------------------------- | |
, sc.[text] collate Latin1_General_CI_AI) > 0 | |
order by | |
so.[xtype], | |
so.[name], | |
po.[name] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment