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

Posted on 2009-02-15
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
    LVL 30

    Expert Comment

    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

    The table are on are on two different servers.
    LVL 30

    Expert Comment

    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

    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

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

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    755 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

    16 Experts available now in Live!

    Get 1:1 Help Now