J
Jason
My previously posted question had to do with a query that would look in two
tables and pull the correct address for a customer depending on the dates of
the secondary address table:
Main address Table:
CustID
Address
City
ST
Zip
Secondary Address Table;
CustID
Begin_Address_Date
Expire_Address_Date
Address
City
ST
Zip
I had a response from Beetle that partially solved the issue for me:
----------
SELECT tblCustomer.FirstName,
IIf([BeginDate]<=Date() And [ExpireDate]>=Date(),[Address2],[Address])
AS CurrentAddress
FROM (tblCustomer INNER JOIN tblMainAddress ON tblCust.CustID =
tblMainAddress.CustID) INNER JOIN tblSecondAddress ON tblCust.CustID =
tblSecondAddress.CustID;
----------
The problem now is that for each customer ID in the Main table, there may
exist the same customer with multiple addresses (the IDs in both tables
match). How can I modify the script so it returns ONLY the address meeting
the date criteria?
See below for full thread:
-------------
Would be slightly easier if you can at least rename the fields in the
secondary table to Address2, City2, etc. and use a query like;
SELECT tblCustomer.FirstName,
IIf([BeginDate]<=Date() And [ExpireDate]>=Date(),[Address2],[Address])
AS CurrentAddress
FROM (tblCustomer INNER JOIN tblMainAddress ON tblCust.CustID =
tblMainAddress.CustID) INNER JOIN tblSecondAddress ON tblCust.CustID =
tblSecondAddress.CustID;
You'll need to add additional IIf statements for City, ST & Zip (or you
could
concantenate them in a single IIf statement I suppose).
If you can't change the field names you can still do the above, but you'll
need
to reference [TableName].[FieldName].
tables and pull the correct address for a customer depending on the dates of
the secondary address table:
Main address Table:
CustID
Address
City
ST
Zip
Secondary Address Table;
CustID
Begin_Address_Date
Expire_Address_Date
Address
City
ST
Zip
I had a response from Beetle that partially solved the issue for me:
----------
SELECT tblCustomer.FirstName,
IIf([BeginDate]<=Date() And [ExpireDate]>=Date(),[Address2],[Address])
AS CurrentAddress
FROM (tblCustomer INNER JOIN tblMainAddress ON tblCust.CustID =
tblMainAddress.CustID) INNER JOIN tblSecondAddress ON tblCust.CustID =
tblSecondAddress.CustID;
----------
The problem now is that for each customer ID in the Main table, there may
exist the same customer with multiple addresses (the IDs in both tables
match). How can I modify the script so it returns ONLY the address meeting
the date criteria?
See below for full thread:
-------------
Would be slightly easier if you can at least rename the fields in the
secondary table to Address2, City2, etc. and use a query like;
SELECT tblCustomer.FirstName,
IIf([BeginDate]<=Date() And [ExpireDate]>=Date(),[Address2],[Address])
AS CurrentAddress
FROM (tblCustomer INNER JOIN tblMainAddress ON tblCust.CustID =
tblMainAddress.CustID) INNER JOIN tblSecondAddress ON tblCust.CustID =
tblSecondAddress.CustID;
You'll need to add additional IIf statements for City, ST & Zip (or you
could
concantenate them in a single IIf statement I suppose).
If you can't change the field names you can still do the above, but you'll
need
to reference [TableName].[FieldName].