select dates where at least one of four fields has text.

jeh

Active Member
Joined
Apr 27, 2002
Messages
250
Hello,

I want to get five fields of data from one table. The catch is that i only want the data when one of the four fields have text in them. These are the field names. [Data](I want to be able and select startdate, and enddate) where[bay1]has text,[bay2]has text, [bay3]has text, and [bay4]has text. There will be dates that all four fields will have text, and somedays where only one field has text. Please help me, I don't have a clue here.

thanks for your time,

Jim
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I think that you will need to create a new coulumn in the query.
NumberFields: IIf(IsNull([Bay1]),0,1)+IIf(IsNull([Bay2]),0,1)+IIf(IsNull([Bay3]),0,1)+IIf(IsNull([Bay4]),0,1)
You can then add a criteria of 1 for the field.

HTH

Peter
 
Upvote 0
Hi Peter,

I don't know what I'm doing wrong , but it errors with "Invaild.(Dot), ot (!).
I'm still trying to figure out how to get around with the queries in Access.

Thanks for your reply!


Jim
 
Upvote 0
If you would like to post the SQL that you have (with out my addition) I will see if I can tweak it for you.

Peter
 
Upvote 0
Hi Peter,

SELECT backwater.date, backwater.bay1, backwater.bay2, backwater.bay3, backwater.bay4, backwater.offb, backwater.offin, backwater.operator
FROM backwater;

this is all done with the 'builder' I don't know how to do it from scratch.

this is what I hoped for. If bay1, bay2, bay3,and bay4 are have a value like "A" ect. (it is only one letter). then I want to see the record. if all four of the fields have a "Z" in them I don't want that record.

I know it is confusing, and the table probably could have been designed better, but I have been given the task of trying to make a report out of it.

Thanks again Peter for your help,

Jim
 
Upvote 0
If I understand you correctly then you want to show any record that does not have 4 Z's in it.
Try this

SELECT backwater.Date, backwater.Bay1, backwater.Bay2, backwater.bay3, backwater.bay4, backwater.offb, backwater.offin, backwater.operator, IIf([Bay1]="z",1,0)+IIf([Bay2]="z",1,0)+IIf([Bay3]="z",1,0)+IIf([Bay4]="z",1,0) AS CountZs
FROM backwater
WHERE (((IIf([Bay1]="z",1,0)+IIf([Bay2]="z",1,0)+IIf([Bay3]="z",1,0)+IIf([Bay4]="z",1,0))<4));


HTH

Peter
 
Upvote 0
Peter: could I bother you for one more step in this query, if it's even possible.

What you have given me works perfect. would it be possible to add something else at the end of this SQL like: Show the records that have a value in the Bay1, Bay2, Bay3, and Bay4 fields. You have screened out the "Z's" for me, Now I need to get rid of the records that have no data in these fields.



SELECT backwater.Date, backwater.Bay1, backwater.Bay2, backwater.bay3, backwater.bay4, backwater.offb, backwater.offin, backwater.operator, IIf([Bay1]="z",1,0)+IIf([Bay2]="z",1,0)+IIf([Bay3]="z",1,0)+IIf([Bay4]="z",1,0) AS CountZs
FROM backwater
WHERE (((IIf([Bay1]="z",1,0)+IIf([Bay2]="z",1,0)+IIf([Bay3]="z",1,0)+IIf([Bay4]="z",1,0))<4));

Thanks again,

Jim
 
Upvote 0
Try:-
Code:
SELECT backwater.Date, backwater.Bay1, backwater.Bay2, backwater.bay3, backwater.bay4, backwater.offb, backwater.offin, backwater.operator, IIf([Bay1]="z",1,0)+IIf([Bay2]="z",1,0)+IIf([Bay3]="z",1,0)+IIf([Bay4]="z",1,0) AS CountZs, IIf(IsNull([Bay1]),1,0)+IIf(IsNull([Bay2]),1,0)+IIf(IsNull([Bay3]),1,0)+IIf(IsNull([Bay4]),1,0) AS CountNulls
FROM backwater
WHERE (((IIf([Bay1]="z",1,0)+IIf([Bay2]="z",1,0)+IIf([Bay3]="z",1,0)+IIf([Bay4]="z",1,0))<4) AND ((IIf(IsNull([Bay1]),1,0)+IIf(IsNull([Bay2]),1,0)+IIf(IsNull([Bay3]),1,0)+IIf(IsNull([Bay4]),1,0))<4));

Peter
 
Upvote 0
Peter -You are good!

I don't know what it says, but man it works great!!

Thank you Sir,

Jim
 
Upvote 0

Forum statistics

Threads
1,221,567
Messages
6,160,540
Members
451,655
Latest member
rugubara

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top