-
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.
-
Works for me when I try your sample code. Just make sure you have a space between SELECT and @@ERROR. Your example doesn't.