• I interprete it as:

    SCOPE_IDENTITY returns the value of the last identity value inserted in the same scope. Since the scope is the whole batch, it doesn't matter if the identity inserted was in the last statement or not.

    This statement inserts an identity value and it belongs to the same batch, so SCOPE_IDENTITY shouldn't return NULL:

    INSERT INTO @idtable (KeyData) VALUES('Test1')

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP