-3

I have a table with ~100 columns, and only one row. Each column is a date, and each entry in a column is a corresponding value. I want to query the table so that it is displayed with only 2 columns: Date, Value.

|--------|--------|--------|--------|--------|--------|
|  Date1 |  Date2 |  Date3 |  Date4 |  Date5 |  Date6 |
|--------|--------|--------|--------|--------|--------|
| Value1 | Value2 | Value3 | Value4 | Value5 | Value6 |
|--------|--------|--------|--------|--------|--------|

What I want:

|--------|--------|
|  Dates | Values |
|--------|--------|
|  Date1 | Value1 |
|--------|--------|
|  Date2 | Value2 |
|--------|--------|
|  Date3 | Value3 |
|--------|--------|
|  Date4 | Value4 |
|--------|--------|
|  Date5 | Value5 |
|--------|--------|
|  Date6 | Value6 |
anesongib
  • 27
  • 4

1 Answers1

2

You should not use this column's design .. but anyway if you need the result for the columns in separated rows you could try using UNION ALL

select 'date1', date1 
from mytable 
union all 
select 'date2', date2 
from mytable 
......
union all 
select 'date100', date100
from mytable 

And as suggested in comment by @akina you could build the query dynamically using INFORMATION_SCHEMA.COLUMNS

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107