简体   繁体   中英

How can I query my Database for any Stored Proc that returns a field/column value of a specific name?

I want to query the metadata of my Database for any Stored Proc that returns the values from a field or column named "bidprice"

I got a great answer here for how to search for Stored Procs that require a specific set of parameters, namely for Stored Procs that have parameters named Unit, Member, BegDate, and EndDate, this:

; WITH T AS (SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@Unit'
UNION ALL
SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@Member'
UNION ALL
SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@BegDate'
UNION ALL
SELECT [specific_name] FROM information_schema.parameters WHERE [parameter_name] = '@EndDate')
SELECT [specific_name] 
FROM T
GROUP BY [specific_name] HAVING COUNT(*) = 4

That works perfectly; and so I hoped that maybe what I needed to find Stored Procs that return a field/column value of a specific name, such as "bidprice" might be something as simple as this:

; SELECT [specific_name] FROM information_schema.COLUMNS WHERE [COL_NAME] = "bidprice"
FROM T

...but trying it in Visual Studio.Server Explorer (right-clicking on the database connection's Tables folder, and then selecting New Query), I get:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'FROM'.

Is [specific_name] wrong for this type of query? Is COLUMNS or [COL_NAME] wrong for this type of query?

I also tried to simplify the query this way:

; SELECT [specific_name] FROM information_schema.COLUMNS WHERE [COL_NAME] = "bidprice"

...but got:

Msg 207, Level 16, State 1, Line 1
Invalid column name 'COL_NAME'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'bidprice'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'specific_name'.

(and the same exact err when removing the prepended ";")

What is the right way to search for Stored Procs that return in their result set (among/amidst whatever else) a field/column named "bidprice"?

You could use sp_describe_first_result_set this returns the metadata from tsql batch. Take a look at https://msdn.microsoft.com/en-us/library/ff878602%28v=sql.110%29.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM