如何从 SQL Server 中的查询中获取列名 [英] How to get column names from a query in SQL Server

查看:62
本文介绍了如何从 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 中的查询中获取列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆