• Andy/jpipes

    Thanks for your help guys but have FINALLY figured this one out - the problem lay in the select scope identity.

    Nasty, nasty bug that lay in our code for years undetected:

    SELECT @out_MessageId = SCOPE_IDENTITY() FROM TableA

    GO

    Should be simply:

    SELECT @out_MessageId = SCOPE_IDENTITY() GO

    Seems as if the query was processing every single row of the table before returning the identity field value. Simple fix but caused LOADS of heartache.

    Stored procedure execution time reduced from 6+ seconds to 40ms.