sql 更新 table - 声明无效
sql update table - statement not working
我的 VBA 中有以下语句:
DoCmd.RunSQL "UPDATE customer SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND Status = ''"
用于更新名为 "customer" 的 table。我可以在我的 table 中看到大约有 20 个条目,其中 customer_id 是 41308408(即,如果我过滤该值的列),每个条目的位置是伦敦或纽约。其中每一项的“状态”列都是空白的。
我执行上面的代码,它编译正常,但它显示 "You are about to update 0 rows"。如上所述,我希望它是 20。有什么想法吗?
也许 status
不是空白,也许它是空的?尝试以下解决方案:
UPDATE customer
SET Status = 'Premier'
WHERE customer_id = 41308408
AND location IN ('London','New York')
AND Status is null
空白大概是数据库中的一个null
。 Null
s 是价值观——它们是价值观的缺失。您不能使用 =
运算符查询它们,您需要使用 is
运算符显式处理它们:
DoCmd.RunSQL "UPDATE customer SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND Status IS NULL"
更新客户 SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND ((Status is null) or length(trim(状态)) = 0)
我的 VBA 中有以下语句:
DoCmd.RunSQL "UPDATE customer SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND Status = ''"
用于更新名为 "customer" 的 table。我可以在我的 table 中看到大约有 20 个条目,其中 customer_id 是 41308408(即,如果我过滤该值的列),每个条目的位置是伦敦或纽约。其中每一项的“状态”列都是空白的。
我执行上面的代码,它编译正常,但它显示 "You are about to update 0 rows"。如上所述,我希望它是 20。有什么想法吗?
也许 status
不是空白,也许它是空的?尝试以下解决方案:
UPDATE customer
SET Status = 'Premier'
WHERE customer_id = 41308408
AND location IN ('London','New York')
AND Status is null
空白大概是数据库中的一个null
。 Null
s 是价值观——它们是价值观的缺失。您不能使用 =
运算符查询它们,您需要使用 is
运算符显式处理它们:
DoCmd.RunSQL "UPDATE customer SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND Status IS NULL"
更新客户 SET Status = 'Premier' WHERE customer_id = 41308408 AND location IN ('London','New York') AND ((Status is null) or length(trim(状态)) = 0)