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)
 How to catch @@ERROR from dynamic SQL in SQL2000?

Author  Topic 

Georgefu
Starting Member

4 Posts

Posted - 2007-09-04 : 13:03:32
Hi,

I try to execute many sql statements through dynamic sql, and log in the errors for each sql based on the @@ERROR value. But the @@ERROR doesn't always return values, in my code below, I did get value for the insert statement ( I usered inset on purpose) and the create table did NOT retune anything.

CREATE PROCEDURE dbo.test1 AS
BEGIN
Declare @sql_stmt1 VARCHAR(4000),
@message varchar(255),
@errnum int
BEGIN
--SELECT @sql_stmt1 = 'CREATE TABLE dbo.xx(y int) '
SELECT @sql_stmt1 = 'inset into dbo.xx VALUES (1) '
select @sql_stmt1 STMT
Exec (@sql_stmt1)
set @errnum = @@ERROR
SELECT @errnum err
end

END
go

Please help.

George

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-09-04 : 13:07:26
Duplicate, locking this thread.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -