简体   繁体   中英

Adding a new field depending on the condition in MS Access

I have five fields in a Query named Status. Lets consider the names of the fields for an easy demonstration as A,B,C,D,E. The Status Query looks something like this

A         B           C           D            E
1         a                                    d
2                     n           o            
3         t           z   
4         r           m           d            
          q           f           j          

I am looking to add a field to the above Query named Description which looks through each record and adds a description. For example if the field A is empty then in the description it must show Failed A. if the field B is empty then it must show Failed B and in the similar way Failed C, Failed D and Failed E. There may also be multiple Fields which are empty for a record. But it must describe which field is empty first for that record. It must show something like this :

A         B           C           D            E        Description
1         a                                    d          Failed C
2                     n           o                       Failed B
3         t           z                                   Failed D
4         r           m           d                       Failed E
          q           f           j                       Failed A

I have tried to use IIF function in the following way

IIF(A is null,Failed A,IIF(B is null),Failed B, IIF(C is null), Failed C,IIF(D is null), Failed D,Failed E)

It doesn't work in this way. How Can I achieve the above? Or where am I going wrong in the code?

我想你需要这个:

"Failed " & IIF(A is null,"A",IIF(B is null),"B", IIF(C is null), "C",IIF(D is null), "D","E")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM