Condition in IIF function doesn't work

Alvein17

New member
Local time
Today, 10:33
Joined
Sep 2, 2021
Messages
29
Hello Guys,

Good day,

i have some trouble in my access table. my query:

Shift: IIF([aoRemarks1]="NON SHIFT","NON SHIFT",[Xshift]), as you can see in the table result below in Shift column not showing the right result.
1631588521168.png


what's wrong with my querry?

1631588572964.png


and i have some problem with same cases. can you correct my querry?

thank you before,

warm regards
Alvein
 
Hi. It might be easier to help you if you could post a sample copy of your db.
 
Shift: IIF([aoRemarks1] Like "*NON SHIFT","NON SHIFT",[Xshift])
 
what version is your Access?
 
looks like you have applied arnels solution - otherwise what is the problem?
 
add another "*" (star) at the End:

Shift: IIF([aoRemarks1] Like "*NON SHIFT*","NON SHIFT",[Xshift])
 
Why not have IIF(aoremarks1) ="NON SHIFT",aoremarks1,xshift)
 
Technically, to your original question, "What's wrong with my query?"

Nothing is wrong with the original query because in your sample, you never have [aoRemarks1] equal to just "NON SHIFT" - though that field might contain "NON SHIFT" as part of what is there. The equals-sign says the IIF expression matches EXACTLY or it is not a match. Since the fields contain MORE than "NON SHIFT" it is not a match, so you ALWAYS get the XMatch string - which appeas to be empty.

If I read this correctly, you might be able to do something as simple as:

Code:
SELECT FiscalDate, SchedSchedNum, aoRemarks1, XShift, IIF( INSTR( 1, aoRemarks1, "NON SHIFT", vbTextCompare ) > 0, "NON SHIFT", aoRemarks1 ) FROM Shift ;

That is, ask it to look for the sub-string in that longer string. The vbTextCompare style of comparison ignores case by default and will return 0 if the sub-string is not found in the main string.
 
Technically, to your original question, "What's wrong with my query?"

Nothing is wrong with the original query because in your sample, you never have [aoRemarks1] equal to just "NON SHIFT" - though that field might contain "NON SHIFT" as part of what is there. The equals-sign says the IIF expression matches EXACTLY or it is not a match. Since the fields contain MORE than "NON SHIFT" it is not a match, so you ALWAYS get the XMatch string - which appeas to be empty.

If I read this correctly, you might be able to do something as simple as:

Code:
SELECT FiscalDate, SchedSchedNum, aoRemarks1, XShift, IIF( INSTR( 1, aoRemarks1, "NON SHIFT", vbTextCompare ) > 0, "NON SHIFT", aoRemarks1 ) FROM Shift ;

That is, ask it to look for the sub-string in that longer string. The vbTextCompare style of comparison ignores case by default and will return 0 if the sub-string is not found in the main string.
Hello The Doc Man,

thank you, yes i mean contains not equal. i would try first and i will update the result
 

Users who are viewing this thread

Back
Top Bottom