Solved

How to convert column into row data

Posted on 2013-11-05
4
623 Views
Last Modified: 2013-11-13
I have a table with 6 columns , and each holds a integer value
ID
SIZEXXL
SIZEXL
SIZEL
SIZEM
SIZES
I want to convert these six columns into one column called Size.

SO column size would hold all five values
SIZEXXL
SIZEXL
SIZEL
SIZEM
SIZES

my new table will be
ID
SIZE
0
Comment
Question by:countrymeister
4 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39625348
I think you would need a new structure that looks like:

ID
SIZE
SomeValue

The way you get that is to use a union query:union queryOnce you have that query working, you can then create a maketable query from it to create your new structure.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39627190
>I want to convert these six columns into one column called Size.
Define 'convert'.  Do you wish to import all rows from the old table into this new table with the ID-Size columns?   If true, take fyed's query above, and add as the first line INSERT INTO YourNewTable (ID, Size, SomeValue), and that'll do it.
0
 
LVL 1

Author Comment

by:countrymeister
ID: 39627966
I understand that fyed's query will work
How about this pivot query

SELECT ID, [Size], value

FROM
(
select
 ID
,SIZEXXL
,SIZEXL
,SIZEL
,SIZEM
,SIZES
 
  from TableT
 
) x
unpivot
(
  value
  for [Size] in
  (
,SIZEXXL
,SIZEXL
,SIZEL
,SIZEM
,SIZES

)
) u
0
 
LVL 40

Expert Comment

by:Sharath
ID: 39635327
Post some sample data with expected result
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
T-SQL: Do I need CLUSTERED here? 13 45
Text file into sql server 5 27
SQL Query Help Top 1 and Distinct? 6 26
SQL Server Error 21 8 25
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question