Running another script from within a script

Posted on 2005-05-05
Last Modified: 2010-03-19
In Oracle I simply use the
@c:\script.sql command
How do I execute another script from within a script in SQLServer?

Question by:orcl8i_dba_2000
    LVL 34

    Expert Comment

    by:Brian Crowe
    I'm not familiar with Oracle but it sounds like you're trying to call one stored procedure from with another.


    EXECUTE myOtherProc {parameter1, parameter2, ...n}

    Author Comment

    I am trying to call sqlfile2.sql from inside sqlfile1.sql
    LVL 10

    Expert Comment

    by:Jay Toops
    You can use osql or isql utility to run SQL script located on the disk file. This is the example to run SQL script located in the C:\SQLScript.sql file:

    EXEC master..xp_cmdshell 'osql -S Servername -U sa -P -ic:\SQLScript.sql'

    See SQL Server Books Online for more information about osql or isql utility and about xp_cmdshell extended stored procedure.
    LVL 10

    Accepted Solution

    Note you can create a string and modify it VIA sql withing your code ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.
    Viewers will learn how the fundamental information of how to create a table.

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now