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  

Add Fields from Record



 
 
Thread Tools Display Modes
  #1  
Old May 5th, 2010, 10:56 AM posted to microsoft.public.access.queries
Scott
external usenet poster
 
Posts: 1,119
Default Add Fields from Record

I have two tables. One has a unique PersonID with a lot of information about
the person (one to one). Another table has one to many records with
addresses associated with people. The 2nd table has an addressID and the
same person can have several address. Each address has an address type. As
it turns out, there is only one address type for each person, which helps me
in what I want to do.

I want to create a table that has a unique PersonID and a field in each
record for two of the types of addresses. In other words, one person has
what we call a HOR address and the same person has a Proposed HOR address. I
want to create a query/table that has the person's ID, a HOR field and a
Proposed HOR field. I want the table to be static, in the sense that I won't
be able to manipulate the records using VB to create a table each time the
query is run, because the query/table will be used to populate a Word
document that gets data from the table.

Ideas? Thanks.
  #2  
Old May 5th, 2010, 01:21 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Add Fields from Record

3 query solution.

Build two queries that return the addresses. One for each type.

SELECT *
FROM AddressTable
WHERE AddressType = "HOR"

SELECT *
FROM AddressTable
WHERE AddressType = "Proposed HOR"

In a third query link those two queries to the Person table using an outer join.

SELECT Person Stuff Fields
, HOR Address fields
, Proposed HOR Address fields
FROM (PersonTable LEFT JOIN queryHORAddresses
ON PersonTable.PersonID = queryHORAddresses.PersonID)
LEFT JOIN queryProposedHORAddresses
ON PersonTable.PersonID = queryProposedHORAddresses.PersonID

Don't create a table to use this data. You should be able to use the
information directly from the query.

If you don't know HOW to use the SQL view to create queries and cannot figure
out the process to make the queries in design view, post back. I will try to
give you some step by step on doing all this in query design view.

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

Scott wrote:
I have two tables. One has a unique PersonID with a lot of information about
the person (one to one). Another table has one to many records with
addresses associated with people. The 2nd table has an addressID and the
same person can have several address. Each address has an address type. As
it turns out, there is only one address type for each person, which helps me
in what I want to do.

I want to create a table that has a unique PersonID and a field in each
record for two of the types of addresses. In other words, one person has
what we call a HOR address and the same person has a Proposed HOR address. I
want to create a query/table that has the person's ID, a HOR field and a
Proposed HOR field. I want the table to be static, in the sense that I won't
be able to manipulate the records using VB to create a table each time the
query is run, because the query/table will be used to populate a Word
document that gets data from the table.

Ideas? Thanks.

 




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 09:27 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.