Solved

How to convert column into row data

Posted on 2013-11-05
4
629 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 48

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 66

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 41

Expert Comment

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

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

691 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