G
Guest
I have search the newsgroup and found some related examples, but not matching
to what I need to do.
I have created Query1 from a table, and I am trying to do a union query on
Query1. Some fields are data and some are text. However, I am creating an IIF
expression on each field to provide a text result. Also, if the Field has a 0
or N value, I don't want to include it in my new query.
My Query looks like this:
RecordID Field1 Field2 Field3 Field4 Field5
123 -1 N N 2 0
124 -1 G L 0 2
125 0 N N 1 2
My Resulting Query should look like this:
RecordID Result
123 Good
123 Press
124 Good
124 Gas
124 Liquid
124 Fahrenheit
125 Temp
125 Fahrenheit
For my SQL statement I have written the following:
SELECT RecordID,iif([Field1]=-1,"Good") FROM Query1 WHERE ([Field1]<>0)
UNION ALL
SELECT RecordID,iif([Field2]="G","Gas") FROM Query1 WHERE ([Field2]<>"N")
UNION ALL
SELECT RecordID,iif([Field3]="L","Liquid") FROM Query1 WHERE ([Field3]<>"N")
UNION ALL
SELECT RecordID,iif([Field4]=1,"Temp",iif([Field4]=2,"Press")) FROM Query1
WHERE ([Field4]<>0)
UNION ALL
SELECT RecordID,iif([Field5]=1,"Celsius",iif([Field5]=2,"Fahrenheit")) FROM
Query1 WHERE ([Field4]<>0);
Thanks in advance.
to what I need to do.
I have created Query1 from a table, and I am trying to do a union query on
Query1. Some fields are data and some are text. However, I am creating an IIF
expression on each field to provide a text result. Also, if the Field has a 0
or N value, I don't want to include it in my new query.
My Query looks like this:
RecordID Field1 Field2 Field3 Field4 Field5
123 -1 N N 2 0
124 -1 G L 0 2
125 0 N N 1 2
My Resulting Query should look like this:
RecordID Result
123 Good
123 Press
124 Good
124 Gas
124 Liquid
124 Fahrenheit
125 Temp
125 Fahrenheit
For my SQL statement I have written the following:
SELECT RecordID,iif([Field1]=-1,"Good") FROM Query1 WHERE ([Field1]<>0)
UNION ALL
SELECT RecordID,iif([Field2]="G","Gas") FROM Query1 WHERE ([Field2]<>"N")
UNION ALL
SELECT RecordID,iif([Field3]="L","Liquid") FROM Query1 WHERE ([Field3]<>"N")
UNION ALL
SELECT RecordID,iif([Field4]=1,"Temp",iif([Field4]=2,"Press")) FROM Query1
WHERE ([Field4]<>0)
UNION ALL
SELECT RecordID,iif([Field5]=1,"Celsius",iif([Field5]=2,"Fahrenheit")) FROM
Query1 WHERE ([Field4]<>0);
Thanks in advance.