[MS ACCESS]根据其他列的内容生成结果列?

时间:2019-11-21 18:07:37

标签: ms-access

例如,我希望能够基于其他列的内容生成一些反馈列。如何在访问中完成此操作?乘员,日期和交易列是从源表中预先确定的,将通过新的添加生成通过/失败和原因。

**Crew**  l   **Date**     l   **Trade** l **Pass/Fail** l **Cause**
___________________________________________________________________
  123A    l 3/22           l WORK        l Fail          l Crew, Date, Trade
  123B    l ___            l WORK        l Fail          l Crew, Trade
  ____    l ___            l ____        l Pass          l   

1 个答案:

答案 0 :(得分:0)

使用isnull()检查3列中是否有null列,并使用iif()返回结果列:

select [Crew], [Date], [Trade],
  iif(isnull([Crew]) and isnull([Date]) and isnull([Trade]), 'Pass', 'Fail') as [Pass/Fail],
  replace(trim(iif(isnull([Crew]), '', 'Crew ') + iif(isnull([Date]), '', 'Date ') + iif(isnull([Trade]), '', 'Trade')), ' ', ',') as [Cause]
from tablename

结果:

Crew    Date    Trade   Pass/Fail   Cause
123A    3/22    WORK    Fail        Crew,Date,Trade
123B            WORK    Fail        Crew,Trade
                        Pass