Vipul Verma
Vipul Verma

Reputation: 31

SQL UNPIVOT TABLE IN SQL

hi to all i want my all columns header name into a one columns so please help me on this query. here my table structure

I have table like this Named tblInfo

| ID |  Name |Email ID|Age |Gender |

I want to get the result as

|Columns|

ID
Name
Email ID
Age`enter code here
Gender

Thanks In Advance

Upvotes: 0

Views: 42

Answers (1)

Yogesh Sharma
Yogesh Sharma

Reputation: 50173

Why you are not using the INFORMATION_SCHEMA view ?

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = <table_name>

Other way is to use sys.all_objects

SELECT c.name
FROM sys.all_objects b
     JOIN sys.all_columns c ON c.object_id = b.object_id
WHERE b.name = <table_name>
      AND b.type = 'U'; 

Upvotes: 2

Related Questions