'Converting multiple Columns of a table into multiple Rows with all other rows repeating [duplicate]

I have something like this

Id ddf1 ddf2 ddf3 ddf4
1 223 112 221 500

I want something like this

Id ddfs
1 223
1 112
1 221
1 500

I've other columns too in my query. So i want a solution which doesn't effect my other columns.



Solution 1:[1]

you can do something like this. See working fiddle here

select id,ddfs
from yourtable t cross apply
(values ('ddf1',t.ddf1),('ddf2',t.ddf2), ('ddf3',t.ddf3) ,('ddf4',t.ddf4)) v(k,ddfs)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DhruvJoshi