Using a table variable inside of a exists statement

后端 未结 3 1031
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 09:47

I am trying to update a column inside of a table variable based on a condition, the condition being that the ID of the table variable does not exist in a different table:

<
3条回答
  •  我在风中等你
    2021-02-20 10:36

    Here's a version of the previous two using aliases to get around your issue:

    UPDATE @BugRep
    SET IsValid = 'N'
    FROM @BugRep BR
        LEFT JOIN BUG B
            ON BR.BUGCode = B.CODE
    WHERE B.CODE is null
    

    This also avoids the inefficiencies related to "is not null" and "not exists".

提交回复
热议问题