Reputation: 11
I have a IIf statement calculated field in my access query using multiple OR
conditions checking against the same column.
Is there a better way than what I have below I know as this list grows I would like to not have to continue creating an ever growing line.
Any advice would be appreciated.
IIF (field1 = "NAME 1" OR field1 = "NAME 2" OR field1 = "NAME 3"
OR field1 = "NAME 4" OR field1 = "NAME 5"
OR ... Continue to all names added, "True", "False")
Upvotes: 1
Views: 91
Reputation: 32642
Yes, you can do a simple IN
statement:
IIF (field1 IN("NAME 1", "NAME 2", "NAME 3", "NAME 4","NAME 5"), "True", "False")
Alternatively, you can create a table with allowed names, and test if field1 is in that table:
IIF (Exists(SELECT 1 FROM TableNames WHERE Field1 = TableNames.Name), "True", "False")
I recommend the second approach, if you have a long list of things you want to use in multiple places, you should store it in a table, and not copy-paste it around.
Upvotes: 3