How to get column names from a query in SQL Server(如何从 SQL Server 中的查询中获取列名)
问题描述
使用 SQL Server.
Using SQL Server.
我有一个非常广泛的查询,有很多别名等...
I have a very extensive query, with a lot of aliasing, etc...
有没有办法,只使用 SQL(存储过程很好,但不是 PHP 等),从这个查询中获取所有列名的列表?(我意识到我可能不得不将我的查询嵌入到这个解决方案中,但这很好.只是一个临时措施.)
Is there a way, using just SQL (stored proc is fine, but not PHP, etc), to get a list of all column names from this query? (I realize I will have to probably embed my query inside of this solution but that is fine. Just a temporary measure.)
谢谢!
推荐答案
如果您使用的是 SQL Server 2012 或更高版本,则可以利用 sys.dm_exec_describe_first_result_set
If you're using SQL Server 2012 or later you can take advantage of sys.dm_exec_describe_first_result_set
SELECT name
FROM
sys.dm_exec_describe_first_result_set
('Your Query Here', NULL, 0) ;
演示
这篇关于如何从 SQL Server 中的查询中获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 SQL Server 中的查询中获取列名


基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01