所有状态值都相同,然后更新另一个表状态

时间:2015-10-07 10:10:07

标签: sql sql-server-2012

我有两个表,它们的值是

lot-master

event-id   lotid    status
1           1        Awarded
1           2        Awarded
1           3        Awarded

event-master

event-id     status
1             Open

如果已授予所有lot-master状态,则使用event-master查询更新update状态。

1 个答案:

答案 0 :(得分:2)

如果您想这样做,那么您可以尝试这样做,

DECLARE @Count              AS INT = 0,
        @ConditionCount     INT = 0

SELECT @Count = COUNT(1) FROM   lot-MASTER

SELECT @ConditionCount = COUNT(1) FROM  lot-MASTER WHERE  STATUS = 'Awarded'

IF (@ConditionCount = @Count)
BEGIN
    UPDATE EVENT-MASTER
    SET    STATUS = 'Awarded'
END