• Roland C (7/30/2014)


    autoexcrement (7/30/2014)


    UPDATE GLAMF

    SET Activesw = 0

    WHERE ACCTID NOT IN

    (SELECT ACCTID from GLPOST)

    :exclamation: This query will work fine is GLPOST is not empty. But if it is empty, the condition will become :

    WHERE ACCTID NOT IN (null)

    which will never be true neither false !). So no line will be updated, instead of all lines :hehe:

    Not quite.

    NOT IN has the unexpected behaviour you describe when any of the rows in the subquery have the value NULL for the column, not when it's an empty result set. When it's an empty result set, the NOT IN returns all rows, exactly as expected.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass