SQL Server How to select both column and values in SQL query [closed]

snvhrwxg  于 2023-03-11  发布在  其他
关注(0)|答案(1)|浏览(199)

Closed. This question needs details or clarity . It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post .

Closed 1 hour ago.
Improve this question

I want to select both column names and values in a SQL query.

Here is what I have tried but this query only selects column name:

SELECT name 
FROM sys.columns 
WHERE object_id = OBJECT_ID('Table')
osh3o9ms

osh3o9ms1#

To get the values from the columns you need to execute a query that is the result from this:

SELECT CONCAT('SELECT ',STRING_AGG( name,','),' FROM Table') 
FROM sys.columns 
WHERE object_id = OBJECT_ID('Table')

How to execute this statement, in for example a stored procedure, can be found on stackoverflow, for example here: How can I create a dynamic Select statement

相关问题