Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Where have you been all my life! I found the answer I needed in seconds..."

Geography

Where in the world do Tek-Tips members come from?

how to return success from a stored procedure

DougP (MIS)
24 Jul 12 14:32
given this simmpel procedure, I want to know that it updated the record or not to pass something back to my ASP.net WEB page.
Waht is an yweasy way to do this? check for something? is there Success flag triggered if it was good?
[code]
ALTER Procedure [dbo].[sp_SOWUpdateTimeReporting]
@RecordID int,
--'@ResourceLastName nvarchar(50),
--@ResourceFirstName nvarchar(50),
--@Vendor nvarchar(20),
--@ResourceType nvarchar(20),
--@OffshoreOnShore nvarchar(20),
@SPMID nvarchar(20),
@CostTracker nvarchar(20),

@Year int ,
@Month int ,
@Day int ,

@ADActivityCode nvarchar(20),
@HoursWorked float
--@ApprovedBy nvarchar(30),
--@DateWorked datetime,
--@SOWTracker nvarchar(20),
--@WeekEndDate datetime
AS

Update SOWTimeReporting
set
SPMID = @SPMID,
CostTracker = @CostTracker,
[Year] = @Year ,
[Month] = @Month,
[Day] = @Day,
ADActivityCode = @ADActivityCode,
HoursWorked = @HoursWorked
Where SOWTimeReportingUniqueID = @RecordID

DougP

bborissov (Programmer)
24 Jul 12 14:58
If something goes wrong here you will have an exception in your frontend.

Borislav Borissov
VFP9 SP2, SQL Server

DougP (MIS)
24 Jul 12 15:27
Thats what I want? to know?

DougP

DougP (MIS)
24 Jul 12 15:31
so your saying if it fails I get an erro if it succeds I get notihng? can I make a procdure check somehow and retunr "good" update? I am making this. but is there a better way?

CODE

Set @CheckSPMID = (Select SPMID from SOWTimeReporting 
	Where SOWTimeReportingUniqueID = @RecordID)
	If @CheckSPMID = @SPMID
		set @Result = 1
	else
		set @Result = 2
	
	
	Select Result as @Result 

DougP

imex (Programmer)
24 Jul 12 15:45
bborissov (Programmer)
25 Jul 12 2:05
Use TRY and CATCH, maybe in both sides.
Check TRY and CATCH in BOL.
You could use OUTPUT parameter to return value from SP. Or just return some integer value that shows you the result. 0 - success; >0 - error.

Borislav Borissov
VFP9 SP2, SQL Server

Qik3Coder (Programmer)
26 Jul 12 10:41
Doug, If you mix everyone's answers:

CODE

--Your sql code
IF @@Rowcount = 1
begin
 select (Cast 1 as bit) Result
end
else
begin
 select (cast 0 as bit) Result  
end 

If you're using linq, you will be able to directly access the result like this:

CODE

sp_SOWUpdateTimeReportingResult r = dbContext.sp_SOWUpdateTimeReportingResult(myIDVariable);
return r.Result; 

You've got questions and source code. We want both!
There's a whole lot of Irish in that one.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close