Query with if statement

G

Guest

I need to create a query that will display information that will be exported
to Excel. The table is setup so that the [ProductType] field can be either
"TypeA" or "TypeB". From here i created a two calculated fields in queries
so that i could display "TypeA"s in one column in "TypeB"s in another; each
query is designed to store the [Product_ID] and a calculated field: [TypeA]
that displays an "X" in the column. The [Product_ID]s are filtered by the
[ProductType] that are equal to "TypeA". My problem comes when i try to put
all the data together. The query i create to show [Product_ID], [TypeA],
[TypeB]; displays those three columns however all records have "X"s in them
for both [TypeA] and [TypeB] columns. I would assume that i need to create a
IIF statement for the query but i have very little experience with those
statements.

Data output:
Product_ID TypeA Type B
1 X X
2 X X

Should be:
Product_ID TypeA Type B
1 X
2 X
3 X

Thanks for your help.
 
K

kingston via AccessMonster.com

Try this in your two query fields:

TypeA: IIF([ProductType]="TypeA","X","")
TypeB: IIF([ProductType]="TypeB","X","")
I need to create a query that will display information that will be exported
to Excel. The table is setup so that the [ProductType] field can be either
"TypeA" or "TypeB". From here i created a two calculated fields in queries
so that i could display "TypeA"s in one column in "TypeB"s in another; each
query is designed to store the [Product_ID] and a calculated field: [TypeA]
that displays an "X" in the column. The [Product_ID]s are filtered by the
[ProductType] that are equal to "TypeA". My problem comes when i try to put
all the data together. The query i create to show [Product_ID], [TypeA],
[TypeB]; displays those three columns however all records have "X"s in them
for both [TypeA] and [TypeB] columns. I would assume that i need to create a
IIF statement for the query but i have very little experience with those
statements.

Data output:
Product_ID TypeA Type B
1 X X
2 X X

Should be:
Product_ID TypeA Type B
1 X
2 X
3 X

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top