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

Posted on 2009-02-15
Medium Priority
Last Modified: 2013-11-10
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!
Question by:encoredatas
  • 2
  • 2
LVL 30

Expert Comment

ID: 23646860
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.


Author Comment

ID: 23646964
The table are on are on two different servers.
LVL 30

Expert Comment

ID: 23647070
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.
LVL 22

Accepted Solution

PedroCGD earned 2000 total points
ID: 23650018
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.

Author Closing Comment

ID: 31547164
Thanks this really helped. save me lots of time. Thanks once again

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

850 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