本文介紹了如何從 SQL Server 中的查詢中獲取列名的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
使用 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) ;
演示
這篇關(guān)于如何從 SQL Server 中的查詢中獲取列名的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!