473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Transpose Rows to Columns ?

I have records

ID Sku Name Date
2 41 Blair 01/04/03
3 45 John 03/04/03

that should look like...

ID 2 3
Sku 41 45
Name Blair John
.....

and so on. Number of source rows will be fixed (12) so no of target
columns will be 12 too.

Anyone know of a quick way to do this via simple SQL ?

Mar 29 '06 #1
3 18437
bo****@gmail.com wrote:
I have records

ID Sku Name Date
2 41 Blair 01/04/03
3 45 John 03/04/03

that should look like...

ID 2 3
Sku 41 45
Name Blair John
....

and so on. Number of source rows will be fixed (12) so no of target
columns will be 12 too.

Anyone know of a quick way to do this via simple SQL ?

This should work on all RDBMS:
CREATE TABLE Sales(Year INTEGER,
Quarter INTEGER,
Results INTEGER);
SELECT Year,
MAX(CASE WHEN Quarter = 1
THEN Results END) AS Q1,
MAX(CASE WHEN Quarter = 2
THEN Results END) AS Q2,
MAX(CASE WHEN Quarter = 3
THEN Results END) AS Q3,
MAX(CASE WHEN Quarter = 4
THEN Results END) AS Q4
FROM Sales
GROUP BY Year

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 30 '06 #2
I understand SQL 2005 T-SQL has a Pivot command. Would that do it?

Mar 30 '06 #3
ji**********@countrywide.com wrote:
I understand SQL 2005 T-SQL has a Pivot command. Would that do it?

OP didn't state the version....

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: sangeetha | last post by:
Hi, i need to transpose a nx1 matrix to 1xn matrix inorder to multiply with nxn matrix in c language ... can anyone help in this coding ..the nx1 matrix is pi the data type is double *pi..this is...
1
by: Chris Smith | last post by:
Experience Posters, Sorry if this is not the right group to post this question. He is my issue; Is there a way without the use of 3rd party controls, to transpose the rows of a datatable to...
7
by: Leszek Gruszka | last post by:
I wrote an aplication that write something into tableA in sql2000. I want to write the same, but transposed into tableB. Someone can help me? Any example? *** Sent via Developersdex...
8
by: Leszek Gruszka | last post by:
I wrote code, that fill TableA with records by executenonquery. But i want to have second TableB, that will be transposed TableA. My code: Public Sub SQL_Wpis() Dim sSQL As String sSQL =...
1
by: Oonz | last post by:
Hi Friends, How to transpose the columns into rows i want to convert the table which looks like this ID Name HomePhone WorkPhone Email 1 test1 678364 643733 test1@test.com 2 ...
0
by: shantanu | last post by:
I am trying to convert a macro code to c# that will copy the values of a column and paste to anather through paste special. Everything is working fine but the transpose meathod to paste the column...
1
by: lenygold via DBMonster.com | last post by:
Chris Eaton created a SP to to transpose rows to columns : Here is an example of a rowtocol stored proc that takes a SQL statement as the first paramter, a delimiter as the second parameter and the...
1
by: brionesl | last post by:
Hi, I have seen other threads with the same question but I'm not too familiar with Access and their solutions often include writing VB code or very complex SQL statements. What I want to do is...
5
by: jenniferhelen | last post by:
I have been searching threads for a while and found the instructions listed below many times, however when I get to step 6 and select to save, I always receive the following error, "The information...
12
by: jenniferhelen | last post by:
I am working with a query that has 6 columns and 101 rows; I would like to transpose the rows and columns. I have tried using a crosstab query but Access limits the row "fields" to 3 and this was...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.