Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two tables: Table 1 and Table 2. From my ASP.NET page I call a stored procedure to insert (batch insert) records into Table 2 from Table 1 if they match certain criteria. After I sucessfully insert the records into Table 2, I need to delete those records from Table 1.

? How can I check, first within the stored procedure, that the insert was successful? I tried to use @return_value = 0. I also need to communicate back to my asp.net page that there was an error, if in fact the stored procedure results in 1. Between the insert and delete below how best to check for an error -- a TRY CATCH?

If the employee passes the evaluation period, then the record is inserted into table 2 using values from table 1.

SQL
ALTER PROCEDURE [dbo].[TestReturnValue]
AS
    DECLARE @return_value int
    DECLARE @EmpID int
    DECLARE @EvalBeginDate date

BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

INSERT INTO Table_2 (EmpID, EvalBeginDate)
VALUES (@EmpID,@EvalBeginDate)

DELETE FROM Table_1
WHERE EmpID = @EmpID;

END



Thank you for helping a newbie!
Posted
Updated 15-Jan-11 14:17pm
v2

You could use a try/catch or check @@ERROR, 0 indicates success and anything else is an error.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900