Solved

get storedproc return value in dts

Posted on 2006-07-24
5
218 Views
Last Modified: 2008-03-10
Hi,

I have a stored proc which has an update statement. There are 3 cases, it either does the update(n rows), it doesn't do any update(0 rows) or it fails. If it fails I can use the fail task to send myself email and if it succeeds I can send email as well. However, if it doesn't run at all i.e. 0 rows updated then it's neither success nor failure. I would like to know how i can find out if it did not run or didnt do any changes so that I can send email accordingly.

Please advise.

Thanks
0
Comment
Question by:Devsql
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 75 total points
ID: 17170576
Here's one way.  I imagine this will vary greatly by developer.

CREATE PROCEDURE YourProc(@success bit) AS

UPDATE YourTable
SET Column1 = Value1

IF @@ROWCOUNT > 0
   begin
   -- Your Update statement updated at least one record.
   @success =1
  end
else
  begin
  -- Your Update statement did not return any records.  
  @success=0
  end

SELECT @success
GO
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17170868
You cannot return an output parameter to DTS (at least not directly) You will have to resort to returning a resultset containing the variable, as suggested in the previous comment, make sure to alias it.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17171111
Some small modifications to Jim's code (no points please):

CREATE PROCEDURE YourProc()

AS

SET NOCOUNT ON

UPDATE YourTable
SET Column1 = Value1
WHERE <YourConditionGoesHere>

Select @@ROWCOUNT as [RowCount]
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now