Solved

Modifying Table data in Access

Posted on 2011-02-26
4
391 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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