A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Creating a query with one to many all on one line



 
 
Thread Tools Display Modes
  #1  
Old March 6th, 2009, 12:39 AM posted to microsoft.public.access.queries
Jay Oken
external usenet poster
 
Posts: 13
Default Creating a query with one to many all on one line

I have two tables, Parent and Children, with a one-to-many relationship. I
would like to create a query that creates a single record per
parent/children listing the parent and then as many children as they have
listed all in the same record. I assume that I would have to do this with a
SQL query?


  #2  
Old March 6th, 2009, 12:56 AM posted to microsoft.public.access.queries
Ivan Grozney
external usenet poster
 
Posts: 48
Default Creating a query with one to many all on one line

Jay,

Check out
http://www.rogersaccesslibrary.com/O...p#Hookom,Duane

Generic Function To Concatenate Child Records (46 KB)

Works great and shows you different ways to use it.

hth

Vanya





"Jay Oken" wrote:

I have two tables, Parent and Children, with a one-to-many relationship. I
would like to create a query that creates a single record per
parent/children listing the parent and then as many children as they have
listed all in the same record. I assume that I would have to do this with a
SQL query?



  #3  
Old March 6th, 2009, 12:14 PM posted to microsoft.public.access.queries
Jay Oken
external usenet poster
 
Posts: 13
Default Creating a query with one to many all on one line

Thanks Ivan. Any ideas on how to get the concatenated data into separate
fields so that I can export the query to an excel spreadsheet.


"Ivan Grozney" stormovick (ditch) @hotmail.com wrote in message
...
Jay,

Check out
http://www.rogersaccesslibrary.com/O...p#Hookom,Duane

Generic Function To Concatenate Child Records (46 KB)

Works great and shows you different ways to use it.

hth

Vanya





"Jay Oken" wrote:

I have two tables, Parent and Children, with a one-to-many relationship.
I
would like to create a query that creates a single record per
parent/children listing the parent and then as many children as they have
listed all in the same record. I assume that I would have to do this with
a
SQL query?





  #4  
Old March 6th, 2009, 02:08 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 2,364
Default Creating a query with one to many all on one line

Try using a tab character Chr(9) as the second argument to the Concat
function. Of course, that will probably end up showing you a square in
the query, but it will probably put the data into separate cells when
you export to Excel.

If that doesn't work then you could write a ranking query to rank each
child record and then a crosstab query to return the data in multiple fields

SELECT Parent.*
, Children.*
, (SELECT Count(*)
FROM Children as C
WHERE C.ParentID = Parent.ParentID
AND C.ChildID Children.ChildID) as Rank
FROM Parent INNER JOIN Children
ON Parent.ParentID = Children.ParentID

Use that in a crosstab query, that would look something like the following.

TRANSFORM First(Child)
SELECT Parent.ParentID
FROM qRankedChildren
GROUP BY Parent.ParentID
PIVOT Rank

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


Jay Oken wrote:
Thanks Ivan. Any ideas on how to get the concatenated data into separate
fields so that I can export the query to an excel spreadsheet.


"Ivan Grozney" stormovick (ditch) @hotmail.com wrote in message
...
Jay,

Check out
http://www.rogersaccesslibrary.com/O...p#Hookom,Duane

Generic Function To Concatenate Child Records (46 KB)

Works great and shows you different ways to use it.

hth

Vanya





"Jay Oken" wrote:

I have two tables, Parent and Children, with a one-to-many relationship.
I
would like to create a query that creates a single record per
parent/children listing the parent and then as many children as they have
listed all in the same record. I assume that I would have to do this with
a
SQL query?





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:03 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.