@@ERROR returns ''1'' in SQL Server 2005 stored procedure but procedure executes successfully. Please Help?
-
Guys, below is my stored procedure in sql server 2005. The problem is, @@ERROR is returning 1 however the procedure executes successfully and deletes the record. I have a check on front end that if @@ERROR returns 0 then display a ''success'' message otherwise display a "'failure'' message. In this case, ''failure'' message is being displayed however record is being deleted successfully. Please help me where I am doing wrong. ALTER PROCEDURE [dbo].[sp_Teams_DELETE] ( @teamID int ) AS DELETE [dbo].[tbl_Teams] WHERE [TeamID] = @teamID RETURN @@ERROR
-
Answer:
1. Make sure the delete actually worked. 2. Try a workaround by trapping @@error in an integer local variable and then returning that variable. 3. Try printing @@error and see what you have. 4. Might be due to some scope termination issues. Check if the variable that you are assigning the return value of the SP is an integer variable. 5. Return the @@error value in an output variable to the SP and see if that helps. In short, I do not know the exact reason why this is happening without the entire context. But these are some food for thought.
PuraniJe... at Yahoo! Answers Visit the source
Other answers
commitALTER PROCEDURE [dbo].[sp_Teams_DELETE] ( @teamID int ) AS DELETE [dbo].[tbl_Teams] WHERE [TeamID] = @teamID tran A if @@ERROR = 0 commit tran A else rollback tran A RETURN @@ERROR end now if any error data will roll back
Related Q & A:
- How to control the excessive use of ram by SQL Server?Best solution by Database Administrators
- Can I create a second filestream container on an existing SQL Server 2008 database without going offline?Best solution by Database Administrators
- How to upgrade sql server express 2005 to 2008R2?Best solution by Server Fault
- How Do I Configure SQL Server 2005 Backend?Best solution by Server Fault
- How to output the results of an procedure in SQL server?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.