"SQL statement"-find keywords in all stored procedures, keywords are not case-sensitive [Sp_findproc]

Source: Internet
Author: User

Use [EShop]
GO
/****** object:storedprocedure [dbo]. [Sp_findproc] Script DATE:2015/8/19 11:05:24 ******/
SET ANSI_NULLS on
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo]. [Sp_findproc] (@akey varchar (255)) As

--Find keywords in all stored procedures, keywords are not case sensitive
DECLARE @aname as varchar (700)
DECLARE @atext as varchar (8000)
DECLARE @acolid as int
DECLARE @pos as int
DECLARE @start as int
DECLARE @end as int
DECLARE @shorttext as varchar (255)
CREATE TABLE #temp_proctext (OID int IDENTITY (1, 1), name varchar (), text varchar (255), POS int)
Declare proctext_cursor cursor Local for
Select A.name, b.text,b.colid from sysobjects a,syscomments B where a.id=b.id and a.type= ' P '
And b.text like '% ' [e-mail protected]+ '% ' ORDER by a.name,b.colid
Open Proctext_cursor
FETCH NEXT from Proctext_cursor to @aname, @atext, @acolid
while (@ @FETCH_STATUS = 0)
Begin
Set @pos = charindex (@akey, @atext, 1)
while (@pos >0)
Begin
Set @start = @pos-10
If @start <=0
Set @start =1
Set @end = @pos + len (@akey) +20
If @end > Len (@atext)
Set @end = Len (@atext)
Set @shorttext = Substring (@atext, @start, @end-@start)
INSERT into #temp_proctext values (@aname, @shorttext, (@acolid-1) *[email protected])
Set @pos = charindex (@akey, @atext, @end)
End
FETCH NEXT from Proctext_cursor to @aname, @atext, @acolid
End
CLOSE Proctext_cursor
Deallocate proctext_cursor
Select Name,pos,text from #temp_proctext ORDER by OID
drop table #temp_proctext

"SQL statement"-find keywords in all stored procedures, keywords are not case-sensitive [Sp_findproc]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.