【发布时间】:2017-06-09 15:00:53
【问题描述】:
我正在开发一个包含两个需要匹配和更新记录的不同表的数据库。基本上如果两个字符串字段相等,则更新不同的字段。
我无法完全弄清楚。
第一个表IngredientDB包含两个字符串字段Item Number和Ingredient Name
第二个表Table Material Label还包括两个字符串字段MaterialCode和MaterialDescription强>
Ingredient Name 和MaterialDescription 有很多相同的记录,但并非所有记录都相同。
我希望能够
- 匹配
MaterialDescription和Ingredient Name - 将
MaterialCode更新为与项目编号完全相同 对应于Ingredient Name。
所以我尝试使用更新查询和 if 语句,这就是它的样子:
- 字段:材料代码
- 表格:表格材质标签
- 更新至:iif([MaterialDescription]=[Ingredient Name],[Item Number],"NotFound")
- 条件:空白
- 或:空白
当前的问题是所有MaterialCode 记录都被“未找到”填充,这意味着它由于某种原因找不到任何匹配项...
有没有更简单的方法来完成这一切?我错过了什么吗?抱歉,当谈到 Access 的东西时,我是个新手。还在学习!
编辑: 这是我目前所在的image of。箭头表示我要更改的内容。
图像中的代码,当前出现语法错误
UPDATE [Table Material Label] JOIN [IngredientsDB] on [Table Material Label.MaterialDescription] = [IngredientsDB.Item Number]
SET [MaterialCode] = [Item Number]
WHERE [MaterialDescription] = [Ingredient Name]
【问题讨论】: