【问题标题】:All status value is same then update another table status所有状态值都相同,然后更新另一个表状态
【发布时间】:2015-10-07 10:10:07
【问题描述】:

我有两张表,它们的值是

lot-master:

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

event-master:

event-id     status
1             Open

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

【问题讨论】:

  • 那你想要什么? ,不清楚..If all lot-master status is awarded then event-master status update using update query,那你要更新什么?
  • 存储“计算”值(来自其他列)通常是个坏主意。比如给 event-id = 1 加上一个未获奖的lotid,那么event-master的状态就会出错!
  • 用户自动授予的批次主状态
  • 不一定所有的lot-master状态都是Awarded......但是当所有lot-master状态都被授予时,event-master状态是Awarded

标签: sql sql-server-2012


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2016-08-26
    • 1970-01-01
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 2021-09-05
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多