473,668 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transpose into fixed column

7 New Member
Hi all,

I am using SQL 2000, and I have following table with 2 columns, ID and TIME

ID | TIME
A | 07:01
A | 12:05
A | 13:01
A | 15:09
B | 15:07
C | 06:52
C | 12:47
C | 17:03
D | 07:00
D | 18:12
D | 18:57
D | 21:04

Now i want to transpose them into another existing table with 7 fixed columns: ID, T1..T6
So it should be like this:

ID | T1 | T2 | T3 | T4 | T5 | T6
A | 07:01 | 12:05 | 13:01 | 15:09
B | - | - | - | 15:07
C | 06:52 | - | 12:47 | 17:03
D | 07:00 | - | - | 18:12 | 18:57 | 21:04

Have tried using following query

SELECT c.ID,
CASE
WHEN c.Time <= '07:15' THEN c.Time
END AS T1,
CASE
WHEN c.Time > '07:15' AND c.Time <= '12:15' THEN c.Time
END AS T2,
CASE
WHEN c.Time > '12:15' AND c.Time <= '13:15' THEN c.Time
END AS T3,
CASE
WHEN c.Time > '13:15' AND c.Time <= '18:15' THEN c.Time
END AS T4,
CASE
WHEN c.Time > '18:15' AND c.Time <= '19:15' THEN c.Time
END AS T5,
CASE
WHEN c.Time > '19:15' AND c.Time <= '21:30' THEN c.Time
END AS T6
FROM Cards c
WHERE c.Date = '03/20/2007'
ORDER BY c.ID, c.Time

The result is not far from ok.

Any help will be appreciated.

TIA
east7
Jul 22 '09 #1
2 1857
ck9663
2,878 Recognized Expert Specialist
use PIVOT/UNPIVOT

Good luck

--- CK
Jul 22 '09 #2
east7
7 New Member
ck, thanks. Cant find pivot in sql 2000.
However you lead me to this:

SELECT c.ID,

MAX(
CASE
WHEN c.Time <= '07:15' THEN c.Time
END)
AS T1,

MAX(
CASE
WHEN c.Time > '07:15' AND c.Time <= '12:15' THEN c.Time
END)
AS T2,

MAX(
CASE
WHEN c.Time > '12:15' AND c.Times <= '13:15' THEN c.Time
END)
AS T3,

MAX(
CASE
WHEN c.Time > '13:15' AND c.Time <= '18:15' THEN c.Time
END)
AS T4,

MAX(
CASE
WHEN c.Time > '18:15' AND c.Time <= '19:15' THEN c.Time
END)
AS T5,

MAX(
CASE
WHEN c.Time > '19:15' AND c.Time <= '21:30' THEN c.Time
END)
AS T6

FROM Cards c
GROUP BY c.ID
ORDER BY c.ID

Now the result is ok.
Thanks again.
Jul 23 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
1990
by: Raoul | last post by:
It appears that matrixmultiply(A,B) has a side-effect of transposing the second argument (B). Is this supposed to happen? Is there anyway to prevent it from transposing? This shows what happens: #! /usr/bin/env python from numarray import *
4
39315
by: Tuong Do | last post by:
Hi I have a table with data like this ID Type 1 A 1 B 1 C 2 A 2 C
7
12053
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 used through out the program ..now i need this transpose for further calculations.... Kindly help as soon as possible.....if this is not possible kindly suggest me something...
4
11170
by: Otie | last post by:
Hello, I am using the MSFlexGrd Control in VB5. I have 1 fixed row and one fixed column. I am trying to do a sort when the user clicks a column in the FIXED ROW. But when I capture the row number in the click event I get row = 1 if I click on the FIXED row OR the actual row 1. How can I get the grid control to tell me when the user has clicked on the FIXED row and not on row 1 (since they both produce row = 1 and I cannot tell them apart...
6
4960
by: JayDawg | last post by:
Excel has this cool little function where you can copy data, and then paste it transposed so that which runs across the rows now runs down a colum and visa versa. Is there a way in access to create a report that would transpose the data from what is logical. I have a query that has a field for the date (by month) and then additional fields (15 of them) by which I enter in data. So in the Table/Query it is formated such that when the...
0
7273
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 value as row value is not working. Can someone kindly look into the code, if i am missing something. C# Code ------------ private void ManipulateXLS() {
4
4240
by: samitasahu | last post by:
Hi, I m showing College Details in a table in jsp . I want to transpose the column data into rows in the table. How to do that in jsp coding.
4
4035
by: pc_whocares | last post by:
My forehead is flat from pounding. I am building a DLL in VS2005 C++ for use in another software development platform. I am required to pass my array data in/out of the function via a pointer, in this case, to double. The simplest way for me to transpose the array is via addressing its individual elements in the conventional form such as
0
1047
by: east7 | last post by:
Hi all, I have following table with 2 columns ID | TIME ========= A 07:01 A 12:05 A 12:59 A 15:09
0
8367
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2781
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2017
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.