Solved

Modifying Table data in Access

Posted on 2011-02-26
4
389 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

Independent Software Vendors: 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

749 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