Solved

Modifying Table data in Access

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

Accepted Solution

by:
Rey Obrero 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Display multiple images in report 12 85
Resize text 4 16
Why is my report opening in "MAX" view? 7 12
Help with SQl and UNION 7 16
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now