Link to home
Start Free TrialLog in
Avatar of yami_rider
yami_rider

asked on

Execute SQL task based on return value from stored procedure in DTS SQL Execute Task

Not very familure with DTS. However hopefully someone can at least get me started on the right track.

My problem here is I need to act upon a condition, specifically if a record exists in a table or not. So what I have done is the following:

* Created a stored procedure that simply checks for the existance of a record and returns a 1 for true or 0 for false.  This works as I use it in other code, but I am unsure exactly how to implement it in DTS (i.e. call it and get the return value).

* My DTS package needs to call this stored procedure, check the return value and execute either an UPDATE or an INSERT SQL statement into the table.  

My current code thus far works up to this point:

Step 1 DTS package reads in files from a local folder.
Step 2 DTS package will assign some global variables.
Step 3 DTS package will then create a temporary table and insert the records.

Step 4 [This is where I am stuck]
* Find a way to call my existing store procedure that will return 1 (true) or 0 (false).
* If true, update record
* If false, add record



ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yami_rider
yami_rider

ASKER

Thanks.. I will give you the points because you led me in the right direction.  Actually turns out that my initial approach was not the best approach.

I would have to iterate through all records, which to me is ineffecient. I do not want to write up a method to iterate through all records.  Instead I will let SQL and its much more advanced methods of searching for data do it for me.  

What I did was the following:

* Populate temporay table with data. This data is transactional so I have an ID field that has many records but each record has a unique transaction id.  The highest transaction ID being the most recent record.

* Using the SQL Execute task, placed a INSERT statement that added the most recent transaction into my table.  I used the WHERE NOT EXISTS statement to obtain whether or not the record indeed already exists in the table. If it does not, then add most recent transaction. Else finish this stepand go to the next SQL Execute Task, which is a UPDATE statement.

* The UPDATE statement simply queries the most recent transaction in the temp table and updates the existing case in the table with that data.

To me this approach is working.  I am open to any new ideas, or criticism if I am way off and performing this very ineffeciently.

Thanks!