@@ERROR FUNCTION, VALIDATES T-SQL STATEMENTS AS "SET"?

  • HELLO!

    GOOD AFTERNOON,

    Just a question, when we execute the function @@error we know it validates if the previous T-SQL statement raised an error, select, insert, update, delete, but I am not sure if @@error evaluates statements as "set", does it do it?

    For example:

    set @var=@var+10;

    if @@error <> 0

    rollback tran

    @@error is validating the "set" statement?

    thanks for your help!

    have a good day.

  • It should. You can test it out by setting the code to force the error:

    declare @var tinyint

    begin tran

    Print 'I do not expect an error'

    set @var=1;

    if @@error <> 0

    print 'rollback tran'

    else

    print 'nope'

    Print 'I expect an error (SET)'

    set @var=5000;

    if @@error <> 0

    print 'rollback tran'

    else

    print 'nope'

    Print 'I expect an error (SELECT)'

    SELECT @var=5000

    if @@error <> 0

    print 'rollback tran'

    else

    print 'nope'

    ROLLBACK

  • HEY!

    THANKS A LOT!

    IT WAS VERY USEFUL YOUR DEMONSTRATION, AND I SOLVED MY PROBLEM

    🙂

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply