Results 1 to 2 of 2

Thread: Ms Sql @@error

  1. #1
    Join Date
    Feb 2003
    Location
    St. Louis
    Posts
    1

    Exclamation Ms Sql @@error

    When using EXEC() to execute a tsql_string, does it return an @@ERROR value? If I run this code:

    **********************************
    DECLARE @var varchar(8000)
    SET @var = 'SELECT * FROM A'
    EXEC (@var)

    SELECT@@ERROR AS ErrorVar
    **********************************

    @@ERROR returns 0 even when I don't have a table named "A" and an error has happened. Is there anyway around this? I'm running a lot of insert statements and RI has been established. If there is an error, I need to rollback the transaction, but in the above case, it would commit, even though it errored out.

    Thanks for any advice.

  2. #2
    Join Date
    Feb 2003
    Posts
    1,048
    Works for me when I try your sample code. Just make sure you have a space between SELECT and @@ERROR. Your example doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •