【问题标题】:sql update table - statement not workingsql更新表-语句不起作用
【发布时间】:2015-07-16 05:42:00
【问题描述】:

我的 VBA 中有以下语句:

DoCmd.RunSQL "UPDATE customer SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND Status = ''"

这意味着更新一个名为“客户”的表。我可以在我的表中看到大约 20 个条目,其中 customer_id 为 41308408(即,如果我过滤该值的列),每个条目的位置是伦敦或纽约。每一个的“状态”列都是空白的。

我执行了上面的代码,它编译正常,但是它说“你将要更新 0 行”。如上所述,我预计会是 20。有什么想法吗?

【问题讨论】:

  • 你确定它是空白而不是NULL吗?
  • Status 是空白还是NULL?您可以通过选择SELECT * FROM customer WHERE customer_id = 41308408 AND location IN ('London','New York') AND Status = '' 来检查您的 WHERE 子句是否正确。如果没有返回行,则将状态检查更改为 status is null
  • 谢谢大家,确实是null,现在可以正常使用了。

标签: sql ms-access vba sql-update


【解决方案1】:

也许status 不是空的,也许它是空的?尝试以下解决方案:

UPDATE customer 
SET Status = 'Premier' 
WHERE customer_id = 41308408 
AND location IN ('London','New York') 
AND Status is null

【讨论】:

    【解决方案2】:

    空白可能是数据库中的nullNulls 是价值观——它们是价值观的缺失。您无法使用 = 运算符查询它们,您需要使用 is 运算符显式处理它们:

    DoCmd.RunSQL "UPDATE customer SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND Status IS NULL"
    

    【讨论】:

      【解决方案3】:

      UPDATE customer SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND ((Status is null) or length(trim(Status)) = 0)

      【讨论】:

        猜你喜欢
        • 2012-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多