Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query problem

Status
Not open for further replies.

darude

Programmer
Jun 23, 2003
138
US
Good Morning,
I have a query result that looks like this:

StudentID Employer
935465 Dairy Queen
935465 State Street
881095 McDonald's
881095 State House
881095 Verizon

I want my result to look like:

StudentID Employer1 Employer2 Employer3
935465 Dairy Queen State Street
881095 McDonald's State House Verizon

I'm not sure if the answer is a crosstab or if there is another solution. Thank you in advance for taking a look.
 
This can be done with a crosstab and DCount(). As an example if you wanted to find the order dates of the customers in the Northwind Orders table, you could use:
Code:
TRANSFORM First(OrderDate) AS FirstOfOrderDate
SELECT CustomerID
FROM Orders
GROUP BY CustomerID
PIVOT "OrderNumber" & DCount("*","Orders","OrderDate<=#" & [OrderDate] & "# AND CustomerID =""" & [CustomerID] & """");

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thank you so much. So much easier than what I was trying. Have a good day!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top