Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identify by Product Category

Status
Not open for further replies.

ba4crm

Technical User
Dec 19, 2003
92
0
0
US
Hello,
Using Access 2007, I have a table with 2 rows. Group and Product. A group can have one product (PPO or HMO), or both. I would like to get a new column that tells me if said group has both, HMO only, or PPO only.
From:
Group Product
A HMO
A PPO
B PPO
B HMO
C PPO
D HMO
E PPO
F PPO

To
Group Product
A Both
B Both
C PPO Only
D HMO Only
E PPO Only
F PPO Only

I have tried running multiple queries to split up the products into individual columns, without success.

Thanks
 
There may be an easier way but 2 queries

Code:
SELECT tblProduct.Group, Min(IIf([Product]="HMO",IIf([Product]="PMO","Both",[Product]),[Product])) AS Test, Max(IIf([Product]="HMO",IIf([Product]="PMO","Both",[Product]),[Product])) AS Test2
FROM tblProduct
GROUP BY tblProduct.Group;

and the second based on the first of coarse change the names to suit

Code:
SELECT Query1.Group, IIf([Test]=[Test2],[Test],"Both") AS Group2
FROM Query1

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
Sorry posted the wrong first query

Code:
SELECT tblProduct.Group, Min(tblProduct.Product) AS Test, Max(tblProduct.Product) AS Test2
FROM tblProduct
GROUP BY tblProduct.Group

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
Another way with a single query:
SQL:
SELECT [Group], 'Both' AS Product FROM tblProduct GROUP BY [Group] HAVING Count(*)>1
UNION SELECT [Group], Min(Product) FROM tblProduct GROUP BY [Group] HAVING Count(*)=1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top