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