Solved

How to convert column into row data

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Viewers will learn how the fundamental information of how to create a table.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now