연구개발/SQL2005

SP_SEARCH - 저장프로시저에서 단어찾기?

알 수 없는 사용자 2009. 6. 17. 11:28


use master
go

if object_id('master..sp_search') is not null begin
 drop proc sp_search
end
go


create proc sp_search
(
@searchText varchar(100)
, @type int = 0
)
as
if @type <> 1 begin
select  a.name
from sysobjects a
where exists
        (select *
                from syscomments
                where a.id = id
                and text like '%' + @searchText + '%'
        )
and xtype ='P' and category =0
end else begin
select  a.name
from sysobjects a
where exists
        (select *
                from syscomments
                where a.id = id
                and text like '%' + @searchText + '%'
        )
and (xtype ='V') and category =0
end