正如我在这篇文章的标题中所提到的,我正在搜索一种方法,通过查询在Access的表字段上写入,值“DELETED”或“INSERTED”基于2个相似表的比较。 这是我的问题:
SELECT A.[Codice T_CAD], A.[Codice Comp], A.Quantita, A.Desc_ITA, IIf(IsNull(B.[Codice ProJ]),"DELETED","INSERTED")
FROM [Tabella Ponte Distinte 4_0] A
LEFT JOIN qdfImport40RecuperaDistinteComponenti B ON (A.[Codice Comp] = B.[Codice ProJ]) AND (A.[Codice T_CAD] = B.Codice_SEZ)
WHERE (((B.[Codice ProJ]) Is Null));
查询返回3条记录:
Codice T_CAD Codice Comp Quantita Desc_ITA Status
TNAA9012AA03115 ARR0004267007 1 PIANO 50X113 DELETED
TNAA9012AA03115 ARR0004269007 1 PIANO 66X113 DELETED
TNAA9012AA03115 11001317 1 Esagono betulla 9 mm DELETED
而不是:
Codice T_CAD Codice Comp Quantita Desc_ITA Status
TNAA9012AA03115 ARR0004267007 1 PIANO 50X113 INSERTED
TNAA9012AA03115 ARR0004269007 1 PIANO 66X113 INSERTED
TNAA9012AA03115 11001317 1 Esagono betulla 9 mm DELETED
因为表A与第二个查询相比有2个新记录和1个删除。 如何管理受查询返回相应值的记录状态?
编辑:这些是表的结构:
qdfImport40RecuperaDistinteComponenti:
Codice_SEZ Codice ProJ Desc_ITA Quantita
TNAA9012AA03115 ARR0004266007 PIANO 42X113 MDF 1
TNAA9012AA03115 515454 Tasca in plexiglas 1
TNAA9012AA03115 ARR0003671007 TELAIO SCALETTA 1
TNAA9012AA03115 ARR0004268007 PIANO 58X113 MDF 1
TNAA9012AA03115 515453 Tasca in plexiglas 1
TNAA9012AA03115 ARR0003997007 PORTA PREZZO TAVOLO 1
[Tabella Ponte Distinte 4_0]
Codice_SEZ Codice ProJ Desc_ITA Quantita
TNAA9012AA03115 ARR0004266007 PIANO 42X113 MDF 1
TNAA9012AA03115 515454 Tasca in plexiglas 1
TNAA9012AA03115 ARR0003671007 TELAIO SCALETTA 1
TNAA9012AA03115 ARR0004268007 PIANO 58X113 MDF 1
TNAA9012AA03115 515453 Tasca in plexiglas 1
TNAA9012AA03115 ARR0003997007 PORTA PREZZO TAVOLO 1
TNAA9012AA03115 ARR0004269007 PIANO 66X113 MDF SP25 1 (this record must be marked as "DELETED" because there is no more on previous query)
TNAA9012AA03115 ARR0004267007 PIANO 50X113 MDF SP25 1 (this record must be marked as "DELETED" because there is no more on previous query)
TNAA9012AA03115 11001317 Esagono betulla 9 mm 1 (this record must be marked as "INSERTED" because it is a new record).