Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Exception handling in Stored procedure

 
   Database Help (Home) -> Programming RSS
Next:  Secutiry Basics  
Author Message
Abhi

External


Since: Nov 16, 2006
Posts: 1



(Msg. 1) Posted: Thu Nov 16, 2006 10:50 am
Post subject: Exception handling in Stored procedure
Archived from groups: microsoft>public>sqlserver>programming (more info?)

Hi All,

Conside this senario, (I am using SQL Server 2000)

I have to process multiple orders and I have a store procedures to do
this.

This is schema/algorithm of my store proc

Create Proc ProcessOrders
Return ErrorStatus varchar(2000)
Begin
-- This gets informations about all orders those has to be processed
from a seperate table
OPEN CURSOR FOR ALL ORDERS
For EACH Order in CURSOR_ORDERS
PROCESS ORDER (a seperate store proc)
-- I am checking @@error here itself
-- Depending upon Success/Error I want to update
the error status
-- If No error then Status = Status + 'Sucsess'
Else Status = Status + 'Error'
NEXT // Get Next ORDER
CLOSE CURSOR
END

====
PROCESS ORDER

This procedure justs tries to insert a row in a table which has got a
trigger on it. In case of any invalid entry this triggers generates a
warning/error.

I want to trap this error and return any Success/Error status message.

'*****************
Problem,
'*****************
As soon as any "PROCESS ORDER' returns any error whole exeution stops.
Suppose I have to process 5 orders with IDs 501,502,503,504,505 and
order id 502 returns an error then my error message only says
'SUCESS,FAIL.' and main store procedure does not exeutes after that.

I want it to be somthing like this 'SUCCESS,FAIL,FAIL,SUCCESS,SUCCESS'

More Information
----------------------
ORDER table has a trigger on it which checks validity of order(s) and
return ERROR if Order is not valid. Most of time it's this Trigger that
will be generating error in "INSERT INTO ORDER" sql.


Please help. How to acheive this.


If anyone has got any sample code, or any link suggesting how to do
this, Please tell me.

Thanks in advance.
Abhi Rohila

 >> Stay informed about: Exception handling in Stored procedure 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Handling stored procedure for multiple databases - Hi, I am trying to work on a stored procedure that will work with multiple database. I have a prototype of multiple databases. Those are named as the following: ts2_aldkm_app, ts2_aldkp_app, ts2_aldkt_app. The middle part of the database name..

Global Exception Handling - Hi, I'm wondering if there's a means to execute a stored prodecure (or perhaps a single SQL statement) whenever an error is raised (whether manually using RAISERROR or automatically from SQL Server) for means of logging. For example, I'd like to fill a....

Libraries of Stored Procedures and Error Handling - I am trying to design a high quality set of library stored procedures in MSSQL 2005. My issue at hand is I don't know the best way to design error handling. For example, suppose I have the following stack of executed stored procedures in TSQ: Client..

Stored Procedure(s) vs Dynamic Stored Procedure - Hi all, Ok - I have a scenario where I'm trying to build up a sql statement to execute in a stored procedure, depending on the 3 parameters passed in (ie, whether they are <> '') depends on which one of the IF blocks gets run, and subsequently,...

VB in a stored procedure - Is it possible to use VB or VB.NET in a stored procedure? I know that I can call a stored procedure using ADO or ADO.NET from VB or VB.NET, but if I click on Create New Stored Procedure within Enterprise Manager is it possible to use VB(ADO) or..
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]