2014-01-30 76 views
0

我有兩個表。 「RPT_CHG」和「選項」。在RPT_CHG,如果該字段[USER2]可以在表選項領域ApplyToProductCodes然後找到我想要回到我包含[USER2]在[ApplyToPRoductCodes]使用Like的MS Access Query Dlookup?

(IE
RPT_CHG ID的列表字段[USER2] = ICE-GEM0450A

OPTIONS領域ApplyToProductCodes]具有在它的ICE-GEM0450A兩個記錄。

ID#36756包含
ICE-GEM0450A,ICE-GEM0450W,冰GEM0650A,ICE-GEM0650W,ICE-GEM0956A,ICE-GEM0956W,ICE-ICE0250FA,ICE-ICE0250FT,ICE-ICE0250FW,我CE-ICE0250HA,ICE-ICE0250HT,ICE-ICE0250HW,ICE-ICE0320FA,ICE-ICE0320FW,ICE-ICE0320HA,ICE-ICE0320HW,ICE-ICE0400FA,ICE-ICE0400FT,ICE-ICE0400FW,ICE-ICE0400HA,ICE-ICE0400HT,冰ICE0400HW,ICE-ICE0406FA,ICE-ICE0406FW,ICE-ICE0406HA,ICE-ICE0406HW,ICE-ICE0500FA,ICE-ICE0500FT,ICE-ICE0500FW,ICE-ICE0500HA,ICE-ICE0500HT,ICE-ICE0500HW,ICE-ICE0520FA,ICE-ICE0520FW, ICE-ICE0520HA,ICE-ICE0520HW,ICE-ICE0606FA,ICE-ICE0606FT,ICE-ICE0606FW,ICE-ICE0606HA,ICE-ICE0606HT,ICE-ICE0606HW,ICE-ICE0806FA,ICE-ICE0806FW,ICE-ICE0806HA,ICE-ICE0806HW,ICEO- GEM0450A,ICEO-GEM0650A,ICEO-GEM0956A,ICEO-ICE0250FA,ICEO-ICE0250HA,ICEO-ICE0320FA,ICEO-ICE0320HA,ICEO-ICE0400FA,ICEO-ICE0400HA,ICEO-ICE0500FA,ICEO-ICE0500HA,ICEO-ICE0520FA,ICEO,ICE0520HA, ICEO-ICE0606FA,ICEO-ICE0606HA,ICEO-ICE0806FA,ICEO,ICE0806HA

和ID#36757包含
ICE-GEM0450W,ICE-GEM0450A,ICE-GEM0650W,ICE-GEM0956W,ICE-ICE0250FT,ICE-ICE0250FW,ICE-ICE0250HT,ICE-ICE0250HW,ICE-ICE0320FA,ICE- ICE0320FW,ICE- ICE0320HA,ICE- ICE0320HW,ICE- ICE-ICE0400FW,ICE-ICE0400HT,ICE-ICE0400HW,ICE-ICE0406FA,ICE-ICE0406FW,ICE-ICE0406HA,ICE-ICE0406HW,ICE-ICE0500FT,ICE-ICE0500FW,ICE-ICE0500HT,ICE-ICE0500HW,ICE-ICE0520FA,冰ICE0520FW,ICE-ICE0520HA,ICE-ICE0520HW,ICE-ICE0606FT,ICE-ICE0606FW,ICE-ICE0606HT,ICE-ICE0606HW,ICE-ICE0806FW,ICE-ICE0806HW,ICE-ICE1006FW,ICE-ICE1007FW,ICE-ICE1007HA,ICE-ICE1007HW, ICE-ICE1406FA,ICE-ICE1406FW,ICE-ICE1406HA,ICE-ICE1406HW,ICE-ICE1407FA,ICE-ICE1407FW,ICE-ICE1407HA,ICE-ICE1407HW,ICE-ICE1806FW,ICE-ICE1806HW,ICE-ICE1807FW,ICE-ICE1807HW,冰ICE2106FW,ICE-ICE2106HW,ICE-ICE2107FW,ICE-ICE2107HW,ICE-MFI0500W,ICE-MFI0800W,ICE-MFI1256W,ICEO-GEM0450A,ICEO-GEM0650A,ICEO-GEM0956A,ICEO-ICE0250FA,ICEO-ICE0250HA,ICEO,ICE0320FA, ICEO-ICE0320HA,ICEO-ICE0400FA,ICEO-ICE0400HA,ICEO-ICE0500FA,ICEO-ICE0500HA,ICEO,ICE05 20FA,ICEO-ICE0520HA,ICEO-ICE0606FA,ICEO-ICE0606HA,ICEO-ICE0806FA,ICEO-ICE0806HA,ICEO-ICE1006FA,ICEO-ICE1006HA,ICEO-ICE1406FA,ICEO-ICE1406HA,ICEO-ICE1806FW,ICEO-ICE1806HW,ICEO-ICE2106FW, ICEO-ICE2106HW,ICEO-MFI0500A,ICEO-MFI0800A,ICEO,MFI1256A

所以我的查詢會吐出

ID 
36756 
36757 

我嘗試了好幾種可能的方法和他們都不做我想做的。

我嘗試:

ID:DLookUp("[ID]","OPTIONS","[USER2]" Like [ApplyToProductCodes])

這並沒有給一些1300記錄所期望的結果第一個可用的記錄。我錯過了什麼?我應該使用不同的方法嗎?請指教。謝謝!

回答

0

認爲這是你所尋求的查詢:

SELECT RPT_CHG.USER2, OPTIONS.ID 
FROM RPT_CHG, OPTIONS 
WHERE (((OPTIONS.ApplyToProductCodes) Like "*" & [RPT_CHG].[USER2] & "*")); 

根據我的(略有修改)的測試數據,它返回

USER2   ID 
--------------- ----- 
ICE-GEM0450A  36756 
ICE-GEM0450A  36757 
IAMSOSMART-SMRT 36757 
+0

純粹的天才,謝謝了! – Detailmp3