Wrox Programmer Forums
|
BOOK: Access 2010 VBA Programmer's Reference
This is the forum to discuss the Wrox book Access 2010 Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison; ISBN: 978-0-470-59166-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2010 VBA Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2014, 02:39 PM
Authorized User
 
Join Date: Nov 2011
Posts: 20
Thanks: 7
Thanked 0 Times in 0 Posts
Default Flatten a Single Relational Table

Hello authors,

I could not find any vba code in the book to perform the following. Please offer some support.

I have a table StudentResults(StudentName, CourseName, Grade) containing the following sample data :

John, C100, A
John, C101, B+
Betty, C100, A-
Betty, C200, B
Betty, C201, B-
...etc

I need to flatten it so that it becomes as follows :

C100 C101 C200 C201
John A B+ nil nil
Betty A- nil B B-

Hope you could provide vba code to create it

Thank you.
 
Old May 7th, 2014, 04:41 PM
Authorized User
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi,

Do you mean SQL to query your table and provide the results in the format you show? You need to create a crosstab query.

Code:
TRANSFORM First(StudentResults.Grade) AS FirstOfGrade
SELECT StudentResults.StudentName
FROM StudentResults
GROUP BY StudentResults.StudentName
PIVOT StudentResults.CourseName;
The above SQL should help.

Malc.
The Following User Says Thank You to malcolmdixon For This Useful Post:
frdata (May 8th, 2014)
 
Old May 8th, 2014, 04:04 AM
Authorized User
 
Join Date: Nov 2011
Posts: 20
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Thats great!

I thought crosstab query can only be used for summary purposes.

This is something useful and more importantly, easy to use.

Thanks so much
 
Old May 8th, 2014, 05:45 AM
Authorized User
 
Join Date: Oct 2010
Posts: 64
Thanks: 0
Thanked 16 Times in 16 Posts
Smile

Glad it helped, don't forget to press the Thanks button

Malc.





Similar Threads
Thread Thread Starter Forum Replies Last Post
N Level elements in single table sophia ASP.NET 4 General Discussion 6 December 14th, 2011 10:12 AM
Retrieving a single value from a single column in a single row? Ron Howerton LINQ 2 May 17th, 2011 08:46 AM
Multiple views of single table jatatman ASP.NET 3.5 Basics 1 June 2nd, 2008 01:34 AM
Get a Single Data Value from a Table pencilneck Visual Studio 2005 1 January 8th, 2008 02:55 PM
Concatenate multiple records from table to single Ron Howerton SQL Language 6 August 23rd, 2004 08:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.