如何在访问中定义如果[field1] =“window”,[field2] =“door”,[field3] =“wall”那么[field4] =“Building”
答案 0 :(得分:2)
1)创建一个新查询,但不是向设计器添加一个或多个表,而是在右键单击设计器并选择“SQL View”之前取消表选择器(或者,从“views”下拉列表中选择该选项功能区或工具栏最左侧的菜单。)
2)添加以下SQL代码(假设我已正确理解您的伪代码):
UPDATE MyTableName SET Field4 = 'Building'
WHERE (Field1 = 'Window') And (Field2 = 'door') And (Field3 = 'wall');
3)从功能区或工具栏中选择“运行”(它有一个感叹号图标)。
您也可以使用设计器执行此操作,但我个人觉得直接编写SQL代码更方便。
根据评论更新:根据特定条件以某种方式指定Field4
,您可以使用IIf
:
UPDATE MyTableName
SET Field4 = IIf(Field3 Is Null, 'Apartment', 'Building')
WHERE (Field1 = 'Window') And (Field2 = 'door') And ((Field3 Is Null) Or (Field3 = 'wall'))
答案 1 :(得分:0)
UPDATE MyTableName SET Field4 = 'Building'
WHERE (Field1 = 'Window') And (Field2 = 'door') And ((Field3 Is Null) And (Field3 = 'wall'));