How do I Execute stored procedure and if true(1) is returned Execute another stored procedure.

I have a stored procedure that loops through a list of Phone Numbers. The Stored Procedure returns 1 if the Phone Number is found on the table. If it is found I want to pass in the phone number ID one of the Package Level variable in the For Each Loop Container to the Second procedure to Flag another table. If it is not found I don't want to execute the second one but continue checking the next number in the loop. Thanks!
Who is Participating?
PedroCGDConnect With a Mentor Commented:
You want to to all the work in SSIS?
If true, simple add a SQL Task that calls a stored procedure with an output parameter that send the value to a SSIS variable, and use the expression and constraint between task to apply the condition you want.
Have you considered using an UPDATE/JOIN to do this kind of work rather than doing it iteratively?
UPDATE DestinationTable
SET Flag = 1
FROM DestinationTable D, SourceTable S
WHERE D.Phone_Number  = S.PhoneNumber
Assuming the databases are on the same server this is going to be a lot simpler and a hell of a lot faster.

encoredatasAuthor Commented:
The table are on are on two different servers.
Is there any particualr logic in the stored procedures or are they just looking for phone numbers on one side and then inserting them on the other?
I don't want to get off track but basically even using a slow linked server will be quicker than looking phone numbers up one at a time and transferring accross.
encoredatasAuthor Commented:
Thanks this really helped. save me lots of time. Thanks once again
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.