split multiple columns into multiple rows - UNPIVOT


/ Published in: SQL
Save to your folder(s)

<p>UNPIVOT a table to create more rows using two approaches</p>

<p>Convert this...</p>

<pre>
K North South East West
0 1 0 0 0
1 0 1 0 0
2 0 0 1 0
3 0 0 0 1
</pre>

<p>... to this...</p>

<pre>
K PortName PortOk
0 North 1
0 South 0
0 East 0
0 West 0
1 North 0
1 South 1
1 East 0
1 West 0
2 North 0
2 South 0
2 East 1
2 West 0
3 North 0
3 South 0
3 East 0
3 West 1
</pre>

URL: http://stackoverflow.com/questions/3678479/split-multiple-columns-into-multiple-rows

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.