Hi everyone,
I'm trying to make a query off of two tables that is connected/used with another database I don't directly manage.
There is a field called ADDRESS_TYPE in the Delivery Address table that has two values as data options: 'Delivery' and/or 'Contact Address'. The Delivery Address table is linked to the Customer Table. One customer can have more than one entry in the Delivery Address table. It's a one-to-many relationship.
Here's the issue......I'm trying to create a query that lists each customer once, with the primary chosen ADDRESS_TYPE entry (which is usually Delivery)....but the problem I'm facing is that there are some instances where there are two entries for the customer with both a 'Delivery' and 'Contact Address' entry.
What I'd like to achieve is a query that can do the following:
If [ADDRESS_TYPE]="Delivery" then use this and nothing else. If there is no "Delivery" but [ADDRESS_TYPE]="Contact Address" then use this instead. But If there is both "Delivery" and "Contact Address" then only use "Delivery".
So far the flowing SQL is the closest I can get to identifying each value, but it of course returns multiple results for the same company where that company has both values.
Am I asking for too much here?!
I'm trying to make a query off of two tables that is connected/used with another database I don't directly manage.
There is a field called ADDRESS_TYPE in the Delivery Address table that has two values as data options: 'Delivery' and/or 'Contact Address'. The Delivery Address table is linked to the Customer Table. One customer can have more than one entry in the Delivery Address table. It's a one-to-many relationship.
Here's the issue......I'm trying to create a query that lists each customer once, with the primary chosen ADDRESS_TYPE entry (which is usually Delivery)....but the problem I'm facing is that there are some instances where there are two entries for the customer with both a 'Delivery' and 'Contact Address' entry.
What I'd like to achieve is a query that can do the following:
If [ADDRESS_TYPE]="Delivery" then use this and nothing else. If there is no "Delivery" but [ADDRESS_TYPE]="Contact Address" then use this instead. But If there is both "Delivery" and "Contact Address" then only use "Delivery".
So far the flowing SQL is the closest I can get to identifying each value, but it of course returns multiple results for the same company where that company has both values.
Code:
IIf([ADDRESS_TYPE]= "Delivery","Delivery",IIf([ADDRESS_TYPE]="Registered Address","Registered Address", ""))
Am I asking for too much here?!