更新 Access 中的多值字段

发布于 2024-11-07 16:28:06 字数 277 浏览 0 评论 0原文

我在 Access 中创建了一个查找表来提供列的可能值。现在,我需要使用转换列之前的数据更新此列。我无法找出可行的 SQL 查询。我不断收到错误“更新或删除查询不能包含多值字段。”我的研究表明我只需要设置该列的值,但这总是更新 0 条记录:

UPDATE [table_name] SET [column_name].Value = 55 WHERE [table_name].ID = 16;

我知道如果我将其更改为更新文本列,则该查询将起作用,因此这绝对是该列的问题。

I have created a lookup table in Access to provide the possible values for a column. Now I need to update this column with the data it had before I converted the column. I am unable to figure out a SQL Query that will work. I keep getting the error "An UPDATE or DELETE query cannot contain a multi-valued field." My research has suggested that I just need to set the value of the column but this always updates 0 records:

UPDATE [table_name] SET [column_name].Value = 55 WHERE [table_name].ID = 16;

I know this query will work if I change it to update a text column, so it is definitely a problem with just this column.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

两仪 2024-11-14 16:28:06

如果您要向多值字段添加值,请使用追加查询。

INSERT INTO table_name( [column_name].Value )
VALUES (55)
WHERE ID = 16;

如果您想要更改多值字段中存在的一个特定值,请使用 UPDATE 语句。例如,要将 55 更改为 56 ...

UPDATE [table_name]
SET [column_name].Value = 56
WHERE [column_name].Value = 55 And ID = 16;

请参阅 在查询中使用多值字段了解更多信息。

If you're adding a value to your multi-valued field, use an append query.

INSERT INTO table_name( [column_name].Value )
VALUES (55)
WHERE ID = 16;

If you want to change one particular value which exists in your multi-valued field, use an UPDATE statement. For example, to change the 55 to 56 ...

UPDATE [table_name]
SET [column_name].Value = 56
WHERE [column_name].Value = 55 And ID = 16;

See Using multivalued fields in queries for more information.

撕心裂肺的伤痛 2024-11-14 16:28:06

我已经弄清楚了!这确实是违反直觉的!您必须使用 INSERT 语句来进行更新。

-- Update a record with a multi-valued field that has no value
INSERT INTO [table_name] ( [[column_name].[Value] )
VALUES(55)
WHERE [table_name].ID = 16;

这让我很困惑,因为我期待一个 UPDATE 语句。我认为它实际上将一条记录插入到一​​个隐藏表中,该表用于将多个值与该列相关联。

I have figured this out! It certainly was counter-intuitive! You have to use an INSERT statement to do the update.

-- Update a record with a multi-valued field that has no value
INSERT INTO [table_name] ( [[column_name].[Value] )
VALUES(55)
WHERE [table_name].ID = 16;

This confused me because I was expecting an UPDATE statement. I think it actually inserts a record into a hidden table that is used to associate multiple values with this column.

我为君王 2024-11-14 16:28:06

我正在使用 Sharepoint,我将表创建为多值字段,在使用 INSERT INTO 语句时遇到错误,返回 Sharepoint 更改为非多值字段,但这并没有不修它。

使用多值字段重新创建了表,INSERT INTO 工作得很好。

I am working with Sharepoint, I created the tables as multi-value fields, ran into the error with my INSERT INTO statement, went back to Sharepoint to change to non-multi-value fields, but that didn't fix it.

Recreated the table without using multi-value fields, and the INSERT INTO worked just fine.

热鲨 2024-11-14 16:28:06

不要使用 .value 部分

UPDATE [table_name] SET [column_name] = 55 WHERE [table_name].ID = 16;

do not use the .value part

UPDATE [table_name] SET [column_name] = 55 WHERE [table_name].ID = 16;
暗地喜欢 2024-11-14 16:28:06
INSERT INTO Quals (cTypes.[value])
SELECT Quals_ContractTypes.ContractType
FROM Quals_ContractTypes
WHERE (Quals.ID = Quals_ContractTypes.ID_Quals);
INSERT INTO Quals (cTypes.[value])
SELECT Quals_ContractTypes.ContractType
FROM Quals_ContractTypes
WHERE (Quals.ID = Quals_ContractTypes.ID_Quals);
把回忆走一遍 2024-11-14 16:28:06

我得说我不太明白你的问题,但我在你的查询中看到了一些奇怪的东西。试试这个:

UPDATE [table_name] SET [column_name]= 55 WHERE [table_name].ID = 16;

更新
看看这个< /a> 链接:它有一个示例

UPDATE Issues 
SET Issues.AssignedTo.Value = 10
WHERE (((Issues.AssignedTo.Value)=6) 
AND ((Issues.ID)=8));

注释

您应该始终包含 WHERE
子句仅标识
您要更新的记录。
否则,您将更新记录
你并不打算改变。一个
更新不包含的查询
WHERE 子句更改中的每一行
桌子。您可以指定一个值
改变。

I gotta say I didn't understand very well your problem but I saw something strange in your query. Try this:

UPDATE [table_name] SET [column_name]= 55 WHERE [table_name].ID = 16;

UPDATE:
Look at this link: it has an example

UPDATE Issues 
SET Issues.AssignedTo.Value = 10
WHERE (((Issues.AssignedTo.Value)=6) 
AND ((Issues.ID)=8));

NOTES

You should always include a WHERE
clause that identifies only the
records that you want to update.
Otherwise, you will update records
that you did not intend to change. An
Update query that does not contain a
WHERE clause changes every row in the
table. You can specify one value to
change.

浅忆 2024-11-14 16:28:06

多值字段是指具有带列的表的 Access 数据库,允许您选择多个值,如组合复选框列表。

这些是 SQL 无法使用的唯一 Access 类型。我已经测试了所有 Access 查找的可能性,包括硬编码值和查找表。它们工作正常,但如果您有一列具有“允许多个选择”选项,那么您就不走运了。即使使用下面提到的 INSERT INTO ,也不会起作用,因为您会收到关于 INSERTing 到多值字段的类似但不同的错误。

如前所述,最好避免在 Access 外部使用此类表,并专门针对您的外部需求引用表。然后编写一个宏/vba 脚本以使用“辅助”表中的数据更新真实表。

The Multi-Valued field refers to Access databases that have tables with columns, that allow you to select multiple values, like a Combo Checkbox list.

THOSE are the only Access types that SQL cannot work with. I've tested all Access lookup possibilities, including hard-coded values, and lookup tables. They work fine, but if you have a column that has the Allow Multiple select options, you're out of luck. Even using the INSERT INTO as mentioned below, will not work as you'll get a similar but different error, about INSERTing into multi-valued fields.

As mentioned it's best to avoid using such tables outside of Access, and refer to a table specifically for your external needs. Then write a macro/vba script to update the real tables with the data from the "auxiliary" table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文