简体   繁体   English

如何在数据库中查询返回特定名称的字段/列值的任何存储过程?

[英]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" 我想查询数据库的元数据中是否有任何存储过程,这些存储过程从名为“ 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: 我有一个很好的答案在这里了解如何搜索需要一组特定的参数,即对于有冠名单位,会员,BegDate,日期和结束日期,该参数存储的特效存储的特效:

; 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: 因此,我希望也许可能需要找到返回特定名称的字段/列值(例如“ bidprice”)的存储过程,就像下面这样简单:

; 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: ...但是在Visual Studio.Server Explorer中尝试一下(右键单击数据库连接的Tables文件夹,然后选择New Query),我得到:

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

Is [specific_name] wrong for this type of query? 这种类型的查询的[specific_name]错误吗? Is COLUMNS or [COL_NAME] wrong for this type of query? 这种查询类型是否为COLUMNS或[COL_NAME]?

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"? 什么是搜索在结果集中返回的存储过程(其中包括/除其他以外)名为“ bidprice”的字段/列的正确方法?

You could use sp_describe_first_result_set this returns the metadata from tsql batch. 您可以使用sp_describe_first_result_set返回sp_describe_first_result_set批处理中的元数据。 Take a look at https://msdn.microsoft.com/en-us/library/ff878602%28v=sql.110%29.aspx 看看https://msdn.microsoft.com/zh-cn/library/ff878602%28v=sql.110%29.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 存储的proc如何检索正在其运行的数据库的名称? - How can a stored proc retrieve the name of the database it's running in? SQL Server:如何从数据库中的所有存储过程中找到特定值? - SQL Server : how can I find the specific value from all stored procedures in my database? 如果CROSS APPLY为空,则SQL 2008存储的proc不返回任何内容。 我该如何解决? - SQL 2008 stored proc returns nothing if CROSS APPLY is nothing. How can I fix? 如何在存储过程和MSSQL中的函数中将列名作为参数发送 - How to send column name as param in stored proc and function in MSSQL 如何使用SQL中存储过程的值填充结果视图列? - How do I Populate a Result View Column with Value from Stored Proc in SQL? 我在存储过程的脚本 sql 中收到返回值错误 - i get an error with return value in my script sql of stored proc 如何编写一个查询,该查询为一个列中的每个不同值返回一行,并从另一列中返回一个任意值? - How can I write a query that returns a row for every distinct value in one column and returns an arbitrary value from another column? 如何从C#代码进入SQL Server存储过程? - How can I step into a SQL Server stored proc from my C# code? 我应该如何将表名传递到存储过程中? - How should I pass a table name into a stored proc? 使用SQL Server动态管理视图,如何获取存储的Proc参数的默认值? - Using SQL Server Dynamic Management Views, how can I get a Stored Proc Parameter's Default Value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM