By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,837 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

Get a return value from a StoredProcedure

100+
P: 144
hi,

is there anyway to know whether a INSERT/UPDATE/DELETE stored procedured was executed successfully?

for example, if i have the following StoredProcedure:

Expand|Select|Wrap|Line Numbers
  1. create procedure sp_add_employee
  2. @userid int,
  3. @password varchar(20)
  4. as
  5. insert into employee values(@userid,@password)
  6.  
can i get a return value from the stored procedure to know whether the insert is success/failure?

Thank you.
Oct 23 '08 #1
Share this Question
Share on Google+
1 Reply


deepuv04
Expert 100+
P: 227
hi,

use exception handling (try catch blocks) and return some value which will convey the result of the sp.

for example
create procedure sp_add_employee
@userid int,
@password varchar(20)
@Result INT OUTPUT
as
BEGIN
BEGIN TRY
insert into employee values(@userid,@password)
SET @Result = 1
END TRY
BEGIN CATCH
SET @Result = 0
END CATCH

SELECT @Result
END

on executing this if you get the result as 1 means success if 0 failure.


thanks.
Oct 23 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.