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 中的查询中获取列名


- 更改自动增量起始编号? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01