Create table from columns and values in another table.

I have a table, Table1, with several columns and values (columns are different datatypes) ---
COL1      COL2      COL3      COL4      COL5
0                0                 4                 = '3'         1

I want to take both the column name and the value and place into another holding table, Table2 --
COLUMN_NAME      VALUE
COL1                      0
COL2                      0
COL3                      4
COL4                      = '3'
COL5                      1
OzarkSunshineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Najam UddinCommented:
select COLUMN_NAME , VALUE
from tab
unpivot
(
  VALUE
  for COLUMN_NAME  in (COL1 ,COL2 ,COL3,COL4,COL5)
) u;

Open in new window

0
OzarkSunshineAuthor Commented:
My initial column names are different, so I want to select all of them and place them and their value in a row in a new table.
0
Najam UddinCommented:
Can you please elaborate a bit?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

OzarkSunshineAuthor Commented:
I'm afraid I'm not to familiar with unpivot, so I'm reading up on it now.   I tried your solution above (thinking maybe you are answering my question, it just doesn't make sense to me) but I get the following error :

Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'for'.
0
Najam UddinCommented:
Yes I did answer your question. Check the attachments.tableResult.png  Let knowme know if you more detail on anything
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OzarkSunshineAuthor Commented:
I recopied and then didn't get the error message, thanks for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.