I have a table with many fields and additionally several boolean fields (ex: BField1, BField2, BField3 etc.).
I need to make a Select Query, which will select all fields except for boolean ones, and a new virtual field (ex: FirstTrueBool) whose value will equal to the name of the first TRUE Boolean Field.
For ex: Say I have BField1 = False, BField2 = True, BField3 = true, BField4=false, in that case SQL Query should set [FirstTrueBool] to “BField2”. Is that possible?
Thank you in advance.
P.S. I use Microsoft Access (MDB) Database and Jet Engine.
If you want to keep the current architecture (mixed ‘x’ non-null status and ‘y’ non-status fields) you have (AFAIS now) only the option to use
IIF:Of course you can add any
Whereclause you like.EDIT:
Alternatively you can use the following trick:
Set the fields to
nullwhen the flag isfalseand put the order number (iow, “1” for BField1, “2” for BField2 etc.) when the flag istrue. Be sure that the status fields are strings (ie.Varchar(2)or, better,Char(2)in SQL terminology)Then you can use the COALESCE function in order to return the first non-value from the status fields which will be the index number as string. Then you can add in front of this string any text you like (for example “BField”). Then you will end with something like:
Much clearer IMHO.
HTH