Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 The @@error variable

Author  Topic 

cornall
Posting Yak Master

148 Posts

Posted - 2007-05-11 : 06:32:55
I need some help getting what I want from the error variable


RESTORE LOG @dbname
FROM DISK = @fileForProcessing
WITH NORECOVERY
SELECT @saveError = @@error
IF @saveError = 0
PRINT @saveError


If the above code fails I get an error number printed. However the code actualy produces two error codes. one wich specifys why it has failed and one which is a generic error code for the failure to import a log.

How do I get to the other error number? Also can I capture the error messages?

I think what I am asking is does @@error only hold the most recent error number or can I access previous error numbers throw and loop through them?

Hope this makes some sense please ask for any further info needed.

Thanks again

D

nr
SQLTeam MVY

12543 Posts

Posted - 2007-05-11 : 07:12:42
>> does @@error only hold the most recent error number
yes

Are you using v2000 or v2005?

Oops - a v2000 thread.
You won't be able to get anything other than the last error.
You could try running it as dynamic sql and inserting the result into a temp table - that might get all the text output but I doubt it.

Another option is to run using osql and pipe the output to a file then read the file.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

cornall
Posting Yak Master

148 Posts

Posted - 2007-05-11 : 07:13:28
Using 2000
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-05-11 : 07:45:53
If you run it from an application language you might be able to "catch" the errors in the ADO Errors Collection.

I expect this was a typo?

IF @saveError <> 0
PRINT @saveError

Kristen
Go to Top of Page

cornall
Posting Yak Master

148 Posts

Posted - 2007-05-11 : 07:56:34
Yes it is a typo my bad
Go to Top of Page
   

- Advertisement -