MS Access 03-多重“ifs” 在更新查询条件的一个字段中?
我可以运行更新查询并在一个字段中运行多个更新,例如:
“joe doe”更新为 334 & “barry davis”更新为 456 等
基本上我想将名称转换为数字(在我的例子中它将是员工 ID#),并且我有大约 500 名员工,所以一次一个有点不可能。 该表是从 Excel 导入的,我不知道如何执行此预导入操作!
谢谢你的帮助!
Can I run an update query and in one single field run multiple updates like:
"joe doe" updated to 334 & "barry davis" updated to 456, etc
basically I want to convert the name to number (in my case it would be the employee ID#), and I have about 500 employees so one at a time is a little out of the question. the table is import from excel and i don't know how to do this pre-import ethier!
thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然可以在 Access 中使用多个
Iif
语句,但您可能希望在 Access 中使用更新查询来执行此操作。如果没有更多数据源的详细信息,很难确定 - 我假设您的 Access 中已经有一个表,其中列出了用户名及其 ID(我称之为“用户”)。 如果您还没有列出用户名和 ID 的 Access 表,则需要获取一个。
我还假设您已将要更新的数据从 Excel 导入到名为 ExcelImport 的表中。
显然,您需要将我的示例中使用的表名称替换为实际的表名称。
与其替换 Excel 数据中的用户名,不如在 ExcelImport 上添加新列来保存用户 ID 可能更明智。
创建新查询(“在设计视图中创建新查询”)
将 Users 和 ExcelImport 表添加到您的查询中< /p>
通过在 Users 表上的“用户名”字段之间单击并拖动,然后在 ExcelImport 上的“用户名”字段上释放,创建表之间的链接。 这将在此字段上将两个表链接在一起。
将查询类型更改为更新(查询 > 更新查询)
双击 ExcelImport 用户名字段 (或附加用户 ID 字段(如果您正在使用它)将其作为更新目标。 它应该出现在查询设计器下半部分的第一列中。
在此列的“更新到:”字段中,键入 [Users].[UserID]
运行查询。 应出现一个消息框,要求您确认是否要更新 n 行。 单击“确定”进行确认。
鉴于您的数据来自 Excel,您应该检查所有用户 ID 是否已正确设置,因为 Excel 数据中的“Joe Doe”可能在用户表中存储为“Joseph Doe” - 在这种情况下,您需要手动编辑 Excel 数据才能获得匹配项。
Whilst it is possible to use multiple
Iif
statements in Access, you probably want to do this using an update query in Access instead.It's difficult to be certain without more detail of your data sources - I'm assuming here that you already have a table in your Access listing user names to their IDs (which I'm calling Users). If you don't already have an Access table listing user names and IDs, you need to get one.
I'm also assuming you've imported the data you want to update from Excel into a table called ExcelImport.
Obviously, you'll need to substitute the table names used in my example for your actual table names.
Rather than replacing the user name in the Excel data, it might be wiser to add a new column onto ExcelImport to hold the user ID.
Create a new query ("Create a new query in design view")
Add the Users and ExcelImport tables to your query
Create a link between the tables by clicking and dragging between the "user name" fields on the Users table, then releasing over the "user name" field on ExcelImport. This links the two tables together on this field.
Change the type of the query to Update (Query > Update Query)
Double-click on the ExcelImport user name field (or the additional user ID field, if you're using it) to target it for update. It should appear in column one of the bottom half of the query designer.
In the "Update to:" field of this column, type [Users].[UserID]
Run the query. A message box should appear asking you to confirm that you want to update n rows. Click OK to confirm.
Given that your data comes from Excel, you should check that all the user IDs have been correctly set, since it's possible that "Joe Doe" in the Excel data is stored as "Joseph Doe" in the users table - in which case, you'll need to manually edit the Excel data to get a match.
:)
使用唯一
INTEGER
值的标准问题序列表来考虑这一点:超过14种情况,它会生成错误,“查询表达式中的表达式太复杂”。 所以我认为你不会得到接近 500 例的病例!
最好将其设为查找表。
Definitely :)
Consider this using a standard issue Sequence table of unique
INTEGER
values:Beyond 14 cases it generates an error, "Expression too complex in query expression". So I don't think you would get anywhere near 500 cases!
Better make this a lookup table.