sql - 如何从 Ms Access 2007 中的同一个表中进行选择和更新

标签 sql ms-access select

我希望能够选择和更新我当前的库存表

这是我的查询:

UPDATE current_stock 
SET current_stock.quantity =
    (SELECT quantity 
      FROM (SELECT * FROM current_stock) As current_stock1 
    WHERE current_stock1.stock_id=2) 
WHERE stock_id=1;

如果我在没有更新的情况下运行嵌套选择,它工作正常,但将其与更新语句一起使用总是返回错误:操作必须使用可更新查询

实际问题:

我想根据对应的笔记本id通过表Bom_dell中的所需数量字段扣除当前库存数量

语法错误:查询 Express Dlookup 中(缺少运算符)..

我猜嵌套的 Dlookup 不起作用

UPDATE current_stock 
SET current_stock.quantity =
    DLookup("quantity", "current_stock", "stock_id=1")-DLookup("req_quantity","Bom_dell","lap_id=DLookup("lap_id","laptop_info","model_name="Dell Inspiron"")")
WHERE stock_id=1;

根据您的建议,我更改了代码以包含 SELECT 语句并且它有效:

UPDATE current_stock 
SET current_stock.quantity =
    DLookup("quantity", "current_stock", "stock_id=1")-DLookup("req_quantity","Bom_dell","lap_id=(SELECT lap_id FROM laptop_info WHERE model_name='Dell Inspiron')")
WHERE stock_id=1;

我现在需要做的就是添加一个for循环来扣除当前库存表中的所有数量

http://tinyurl.com/7eghddq <<这是我的关系表图像的链接

最佳答案

Domain Aggregate Functions可用于避免“操作必须使用可更新查询”错误。

就您的情况而言,您似乎想要将 stock_id=1 的数量替换为 stock_id=2 的数量。如果我理解正确,请尝试此 UPDATE 查询。

UPDATE current_stock 
SET current_stock.quantity =
    DLookup("quantity", "current_stock", "stock_id=2")
WHERE stock_id=1;

关于sql - 如何从 Ms Access 2007 中的同一个表中进行选择和更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9912419/

相关文章:

c# - ASP.NET MVC C# Razor SQL 1 of 2 几乎相同的更新查询不起作用

php - MySQL 和 PHP 中的多行合并为一行

sql - sql SELECT NULL 和 SELECT 1 的性能比较

java - 用于测试的免费 postgres 托管

mysql - MySql 中的简单搜索

PHP变量不显示值

php - 每隔一个选定项目输出 4 个选定项目

mysql - SQL从值中删除部分文本

ms-access - 查找 VBA 控件对象的部分或页面

arrays - 类型不匹配 VBA 数组