I trying to transform multiple columns with different data type into one column (one row for column), all column would be cast to varchar.
My table to transform:
+----+----------------+-------------------------+------------+------------+
| id | column_varchar | column_datetime | column_int | column_bit |
+====+================+============+==========+===========+===========+===+
| 1 | NULL | NULL | NULL | 1 |
+----+----------------+-----------------+------------+------------+-------+
| 2 | NULL | 2019-01-15 00:00:00.000 | NULL | NULL |
+----+----------------+-------------------------+------------+------------+
| 3 | apple | NULL | NULL | NULL |
+----+----------------+---------------------+------------+------------+---+
| 4 | NULL | NULL | NULL | 0 |
+----+----------------+---------------------+------------+------------+---+
| 5 | NULL | 2018-01-15 00:00:00.000 | NULL | NULL |
+----+----------------+---------------------+------------+------------+---+
| 6 | NULL | NULL | 25 | NULL |
+----+----------------+---------------------+------------+------------+---+
i need create one single column that contains the value of all columns (cast to varchar) with its respective key value, I expect something like:
+----+-------------------------+
| id | column_value |
+====+=========================+
| 1 | 1 |
+----+-------------------------+
| 2 | 2019-01-15 00:00:00.000 |
+----+-------------------------+
| 3 | apple |
+----+-------------------------+
| 4 | 0 |
+----+-------------------------+
| 5 | 2018-01-15 00:00:00.000 |
+----+-------------------------+
| 6 | 25 |
+----+-------------------------+
How can i accomplish this task with SQL-Server? thanks