468,242 Members | 1,515 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

Get a return value from a StoredProcedure

144 100+
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
1 1968
deepuv04
227 Expert 100+
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.

Similar topics

2 posts views Thread by Scott Natwick | last post: by
8 posts views Thread by Nick | last post: by
3 posts views Thread by tshad | last post: by
2 posts views Thread by Hardik Shah | last post: by
7 posts views Thread by Rudy | last post: by
2 posts views Thread by Hrvoje Voda | last post: by
8 posts views Thread by Andrew Robinson | last post: by
4 posts views Thread by =?Utf-8?B?QmFidU1hbg==?= | last post: by
3 posts views Thread by BombDrop | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.