你可以逃离
%
通过指定
escape
select
a.[name]
, b.[text]
, case when a.type in ('fn', 'tf') then 'Function'
when a.type = 'P' then 'Stored Procedure'
when a.type = 'V' then 'View'
else 'Unknown' end as 'ObjectType', a.type
from sysobjects a
inner join syscomments b on a.id = b.id
where b.[text] like '%''PD\%%' escape '\'
order by ObjectType
create procedure dbo.pd_search as
select * from master..spt_values
where number = 1
and name not like 'PD%'
go
create procedure dbo.pd_search_other as
select * from master..spt_values
where number = 1
and name <> 'PD'
go
rextester演示:
http://rextester.com/KPC17170
返回:
+-----------+------------------------------------+------------------+------+
| name | text | ObjectType | type |
+-----------+------------------------------------+------------------+------+
| pd_search | create procedure dbo.pd_search as | Stored Procedure | P |
| | select * from master..spt_values | | |
| | where number = 1 | | |
| | and name not like 'PD%' | | |
+-----------+------------------------------------+------------------+------+