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