[英]SQL Server : how can I find the specific value from all stored procedures in my database?
How can I find the specific value from all stored procedures in my SQL Server database?如何从我的 SQL Server 数据库中的所有存储过程中找到特定值?
To be more specific, I want to know the value that is inserted into the specified column on the specified table.更具体地说,我想知道插入到指定表的指定列中的值。
For example:例如:
dbo.sp_1
, dbo.sp_2
, dbo.sp_3
dbo.sp_1
、 dbo.sp_2
、 dbo.sp_3
[Log]
table which has a [number]
column[Log]
表,其中有一个[number]
列dbo.sp_1 dbo.sp_1
INSERT INTO [dbo].[Log] ([number])
VALUES (1);
dbo.sp_2 dbo.sp_2
INSERT INTO [dbo].[Log] ([number])
VALUES (2);
dbo.sp_3 dbo.sp_3
INSERT INTO [dbo].[Log] ([number])
VALUES (4);
So, the query results I expect are as follows:所以,我期望的查询结果如下:
I found a snippet that was used for a somewhat-similar task, however, I did not have to parse values.我找到了一个用于类似任务的片段,但是,我不必解析值。 This may get you close if you really have to parse the sql.
如果您真的必须解析 sql,这可能会让您接近。 Sorry, the rest of the parsing will be left up to you
抱歉,剩下的解析交给你
DECLARE @NonEscapeTextToFindLike NVARCHAR(MAX) = 'INSERTINTO\[dbo\].\[LOG\](\[number\])VALUES('
DECLARE @NonEscapeTextToFind NVARCHAR(MAX) = 'INSERTINTO[dbo].[LOG]([number])VALUES('
;WITH Procs AS
(
SELECT
StoredProcedure = name,
StoredProcedureText = OBJECT_DEFINITION(object_id),
NoBlankText = REPLACE(REPLACE(REPLACE(REPLACE(OBJECT_DEFINITION(object_id),' ',''),CHAR(9),''),CHAR(10),''),CHAR(13),'')
FROM
sys.procedures
)
SELECT
*,
StartOfPossibleInt = CHARINDEX(@NonEscapeTextToFind, Procs.NoBlankText) + LEN(@NonEscapeTextToFind)
FROM
Procs
WHERE
Procs.NoBlankText LIKE '%'+@NonEscapeTextToFindLike+'%' ESCAPE '\'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.