Solved

get storedproc return value in dts

Posted on 2006-07-24
5
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 66

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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

632 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