2011-01-10 78 views
3
Table name : sp_text 
Column name : obj_Text 

在此列中,所有存储过程都以文本形式存储。在Sql server 2008中使用like子句选择查询

我需要检索所有raiserror%draiserror中的所有存储过程。

例如,SP在其中包含以下raiserror

raiserror('quantity adjustment is not allowed in row no %d', 16, 1, @fprowno) 

我试过下面的查询,但无法得出结果。

select * 
from sp_text_ismail 
where obj_Text like '%raiserror%' 
    and obj_Text like '%/%d%' 

回答

3

使用系统视图sys.sql_modules:更简单。并且您可以使用LIKE中的括号转义%

SELECT OBJECT_NAME(object_id), * FROM sys.sql_modules 
WHERE definition LIKE '%raiserror%[%]d%' 

您也无法选择或筛选存储过程。

+0

什么是“你也不能在存储过程中选择或过滤器”是什么意思? – Gabe 2011-01-10 05:35:46

+0

非常感谢。 – user292848 2011-01-10 05:40:47

-1

您必须在查询中使用转义字符'\',并在最后提及它。你使用了正斜杠而不是后向斜杠。事实上,你可以使用任何字符作为转义字符,但最后你必须提及。

尝试此查询

select * from sp_text_ismail where obj_Text like '%raiserror%' and obj_Text like '%\%d%' ESCAPE '\'