Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

ms access - Update field in one table based on values in another table

I have a status field in a table in which test steps are marked as pass or fail and in another table I have to update test case(testID) as pass if all test step(testID) are pass, and fail test case if one of test is fail.

I have testID field common in both tables.

In the 1st table one column is testID and 5 steps are corresponding to that test ID and they can be pass or fail.

In the 2nd table I have one column in which I have to mark status as pass or fail based on overall 5 steps.

Table 1

X

Table 2

X

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The following queries perform the update in two steps: the 1st query updates those tests which exist and pass, and the 2nd query updates those tests which exist and fail.

Update 'passed' tests:

update table1 t1
set t1.teststatus = 'pass'
where t1.testID in
(
    select t2.testID
    from table2 t2
    group by t2.testID
    having min(t2.status) = max(t2.status) and min(t2.status) = 'pass'
)

Update 'failed' tests:

update table1 t1
set t1.teststatus = 'fail'
where t1.testID in
(
    select t2.testID
    from table2 t2
    where t2.status = 'fail'
    group by t2.testID
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...