Solved

Modifying Table data in Access

Posted on 2011-02-26
4
387 Views
Last Modified: 2012-06-21
I am trying to take data that is the following format in an access table:
Student ID      Event          Date
123             JumpRope     1/1/2010
234             JumpRope     12/2/2010
234             JumpRope     12/2/2010
123             Swing             3/2/2010
234             Run                 2/6/2010
567             Run                 8/7/2010

And switch it to this format:

MemberID     JumpRope        Swing          Run
123              1/1/2010
234             12/2/2010
123                                     3/2/2010
234                                                           2/6/2010
567                                                           8/7/2010

Any suggestions? I have  a union query that does the exact opposite but am stuck on how to write the sql for the query to create the separate columns with data from the same field.

Thank you!!
0
Comment
Question by:MRG_AL
  • 2
4 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 34987567
You can use a crosstab query for that:


TRANSFORM Max(SomeTable.Date) AS MaxOfDate
SELECT SomeTable.StudentID, Max(SomeTable.Date) AS [Total Of Date]
FROM SomeTable
GROUP BY SomeTable.StudentID
PIVOT SomeTable.Event;

Open in new window

0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 34987590


try this one

TRANSFORM Max(Table1.date) AS MaxOfdate
SELECT Table1.[student id]
FROM Table1
GROUP BY Table1.[student id], Table1.date
ORDER BY Table1.date
PIVOT Table1.event;
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 34987615
Small tweak to the crosstab above:


TRANSFORM Max(SomeTable.Date) AS MaxOfDate
SELECT SomeTable.StudentID
FROM SomeTable
GROUP BY SomeTable.StudentID
PIVOT SomeTable.Event;

Open in new window




That returns:



StudentID    JumpRope     Run         Swing   
----------------------------------------------
123          1/1/2010                 3/2/2010
234          12/2/2010    2/6/2010            
567                       8/7/2010            

Open in new window

0
 

Author Closing Comment

by:MRG_AL
ID: 34987633
That worked perfect. Thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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