Solved

How to convert column into row data

Posted on 2013-11-05
4
628 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 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 41

Expert Comment

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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

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. …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

738 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