I have a set of address used for printing labels and I would like to group them.
What I have:
UID CustName LocName State Zip Comments1 Comments2
=========================================================
1 John R1 NC 158631 Foo Bar
2 Smith R2 SC 126543 Bla Bla Bla
What I'm looking for:
Col_1 Col_2 Col_3
=============================
John R1 NC
158631 Foo Bar
Smith R2 SC
126543 Bla Bla Bla
I hope this makes sense.
You need to unpivot the columns of data in the sets of 3 each. If you are using SQL Server 2005+, then you can use CROSS APPLY to get the result:
Note, the datatype must be the same on the columns you are placing together, for example if
zipwas anint, then you would have to convert it to avarcharso you could place the data in the same column ascustname.