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 2005 Forums
 Transact-SQL (2005)
 Get Error

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-09-14 : 10:12:41
Hello,

I have a few procedures for deleting, updating and inserting records on a table. I created an output variable as follows:

@Feedback INT OUTPUT

Is there a way to make @Feedback = 0 or = 1 if an error has occurred or not? And if possible, what kind of error ...

Thanks,
Miguel

Kristen
Test

22859 Posts

Posted - 2007-09-14 : 10:18:56
You would usually catch errors by checking @@ERROR after each statement, or using TRY / CATCH (SQL 2005)

Kristen
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-09-14 : 10:30:22
Hi,

Yes, that is what I usually use after each statement:
SELECT @Feedback = @@ERROR

But I was wondering if I could just have one code line at the end of it.

For example if I have:

Select ...
Insert ...
Delete ...
SELECT @Feedback = @@ERROR

I suppose this would be using a Try/Catch in VS2005, right?

Thanks,
Miguel

Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-09-14 : 10:58:35
I just read this interesting article for Error handling in SQL 2005 and with ASP.NET:

http://www.4guysfromrolla.com/webtech/041906-1.shtml

This seems really nice as I can get the errors on my Stored Procedures and get the error in my Asp.NET code.

Thanks,
Miguel
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-14 : 11:36:52
"But I was wondering if I could just have one code line at the end of it."

Afraid not, as @@ERROR is reset by every SQL Statement.

"I suppose this would be using a Try/Catch in VS2005, right?"

Yup, I reckon that you can get the effect you want using TRY/CATCH

Kristen
Go to Top of Page
   

- Advertisement -