访问中的简单更新查询

时间:2015-06-05 19:14:45

标签: sql ms-access

UPDATE _DATA SET 
[_DATA].Claim_Status = "UNKNOWN", 
[_DATA].State_Filed = "XX", 
[_DATA].Disease_Category = "UNKNOWN"
WHERE 
((([_DATA].Claim_Status) Is Null) AND 
(([_DATA].State_Filed) Is Null) AND 
(([_DATA].Disease_Category) Is Null));

这段代码是我在查询设计中输入标准时得到的。 似乎只有在claim_status,state_filed和disease_category都是null(空)单元格时才会运行。我想运行一个填写" UNKNOWN"在Claim_Status下的空单元格中," XX"在State_Filed等下的int空单元格。条件不应包括" AND"这意味着它们基本上是分开运行的。

任何人都可以帮我吗?

提前致谢。

2 个答案:

答案 0 :(得分:1)

如果所有这三个字段均为zip_plus10 <- function(input) { index <- which(zip.vector == as.numeric(input)) paste('The current temperature for', city[index:(index+10)], state[index:(index+10)], zip.vector[index:(index+10)], 'is: ', temps[index:(index+10)] ) } zip_plus10('90210') [1] "The current temperature for K HI 90210 is: 65" [2] "The current temperature for L ID 90211 is: 66" [3] "The current temperature for M IL 90212 is: 58" [4] "The current temperature for N IN 90213 is: 110" [5] "The current temperature for O IA 90214 is: 57" [6] "The current temperature for P KS 90215 is: 91" [7] "The current temperature for Q KY 90216 is: 90" [8] "The current temperature for R LA 90217 is: 89" [9] "The current temperature for S ME 90218 is: 108" [10] "The current temperature for T MD 90219 is: 109" [11] "The current temperature for U MA 90220 is: 55" #Data set.seed(444) zip.vector <- seq(90200, 90221) city <- LETTERS[1:length(zip.vector)] state <- state.abb[1:length(zip.vector)] temps <- sample(50:110, length(zip.vector)) ,则此查询仅会更新Claim_StatusState_FiledDisease_Category。例如,假设NULLState_Filed,但NULLDisease_Category已填充数据。在这种情况下,您的更新不会更新Claim_Status,因为并非所有三列都是State_Filed。您应该使用三个单独的查询来确保所有NULL列都得到更新,而不管其他两个列是否已填充:

NULL

另外,我个人不会更新UPDATE _DATA SET Claim_Status = 'UNKNOWN' WHERE Claim_Status IS NULL UPDATE _DATA SET State_Filed = 'XX' WHERE State_Filed IS NULL UPDATE _DATA SET Disease_Category = 'UNKNOWN' WHERE Disease_Category IS NULL 字段来包含数据。如果您没有这些列的数据,则表示您没有这些数据。例如,如果您希望NULL状态显示为NULL而不是XX,则执行此操作的位置位于您的表示层或报告您注销此数据,而不是数据库本身。

答案 1 :(得分:1)

你可以使用Nz:

UPDATE 
    _DATA 
SET 
    Claim_Status = Nz(Claim_Status, "UNKNOWN"), 
    State_Filed = Nz(State_Filed, "XX"), 
    Disease_Category = Nz(Disease_Category, "UNKNOWN")
WHERE 
    Claim_Status Is Null 
    OR 
    State_Filed Is Null 
    OR 
    Disease_Category Is Null;