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 » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to put multiple values in one field



 
 
Thread Tools Display Modes
  #1  
Old March 20th, 2009, 06:50 AM posted to microsoft.public.access.tablesdbdesign
Nightmoon Eagle
external usenet poster
 
Posts: 3
Default How to put multiple values in one field

For those with access to an SQL Server, the query works in SQL Server 2000,
2005, and 2005 EXPRESS and is provided below. For those without SQL Server, I
will try to explain my dilemma.

I have a table, tblA which contains locations and the name of the owner and
inhabitants. Each inhabitant/owner has a seperate record in the database with
the same location.

i.e.
Location 1, InhabitantA
Location 2, InhabitantB
Location 2, InhabitantC
Location 3, OwnerA
Location 3, InhabitantD

I want to create a query that shows:
Location 1, InhabitantA
Location 2, InhabitantB InhabitantC
Location 3, OwnerA InhabitantD

or

Field1, Record1.Field2 Record2.Field2 Record3.Field2

Is this possible in Access?

I know it works in SQL as shown by the query below:

SELECT TOP 3 Location, Surnames = replace ((SELECT Surname AS [data()]
FROM tblA WHERE Location = a.Location ORDER BY Surname FOR xml path('')), '
', char(10))
FROM tblA a
WHERE Location IS NOT NULL
GROUP BY Location

Thanks in advance.
NmE
  #2  
Old March 20th, 2009, 09:17 AM posted to microsoft.public.access.tablesdbdesign
Allen Browne
external usenet poster
 
Posts: 11,706
Default How to put multiple values in one field

In Access, we generally call a VBA function that concatenates the related
records and returns them as a string.

This kind of thing:
http://allenbrowne.com/func-concat.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Nightmoon Eagle" wrote in
message
...
For those with access to an SQL Server, the query works in SQL Server
2000,
2005, and 2005 EXPRESS and is provided below. For those without SQL
Server, I
will try to explain my dilemma.

I have a table, tblA which contains locations and the name of the owner
and
inhabitants. Each inhabitant/owner has a seperate record in the database
with
the same location.

i.e.
Location 1, InhabitantA
Location 2, InhabitantB
Location 2, InhabitantC
Location 3, OwnerA
Location 3, InhabitantD

I want to create a query that shows:
Location 1, InhabitantA
Location 2, InhabitantB InhabitantC
Location 3, OwnerA InhabitantD

or

Field1, Record1.Field2 Record2.Field2 Record3.Field2

Is this possible in Access?

I know it works in SQL as shown by the query below:

SELECT TOP 3 Location, Surnames = replace ((SELECT Surname AS [data()]
FROM tblA WHERE Location = a.Location ORDER BY Surname FOR xml path('')),
'
', char(10))
FROM tblA a
WHERE Location IS NOT NULL
GROUP BY Location

Thanks in advance.
NmE


  #3  
Old March 22nd, 2009, 09:45 PM posted to microsoft.public.access.tablesdbdesign
Nightmoon Eagle
external usenet poster
 
Posts: 3
Default How to put multiple values in one field

Allen,

Thank you for the code. I do have a problem with it, though. When using it
in a query, I keep getting the error:

Error 3061: Too few parameters. Expected 1.

the query I have is:

SELECT Location, X, Y, Rotation, TextHeight, ConcatRelated("surname",
"PlotPoints", "Location = " & [Location], [Location], "char(10)") AS Surnames
FROM PlotPoints;

NmE
  #4  
Old March 22nd, 2009, 11:26 PM posted to microsoft.public.access.tablesdbdesign
Nightmoon Eagle
external usenet poster
 
Posts: 3
Default How to put multiple values in one field

Fixed the problems.

Thanks again for the code, Allen.

NmE

"Nightmoon Eagle" wrote:

Allen,

Thank you for the code. I do have a problem with it, though. When using it
in a query, I keep getting the error:

Error 3061: Too few parameters. Expected 1.

the query I have is:

SELECT Location, X, Y, Rotation, TextHeight, ConcatRelated("surname",
"PlotPoints", "Location = " & [Location], [Location], "char(10)") AS Surnames
FROM PlotPoints;

NmE

 




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 10:12 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.