简体   繁体   中英

How to Execute Multiple Queries in a order

I have 26 queries to generate final output I want to automate the process and Execute all 26 queries one after another

how to execute all with a single click in the stepwise order

This is a sample query only.

CREATE PROCEDURE Your_Procedure_Name
AS 
BEGIN

    Write your First Query;

    Write your Second Query;

    Write your Third Query;

    .
    .
    .

    Write your Last Query;

END

And then execute the procedure using:

EXEC Your_Procedure_Name;

It will execute your queries in the above order.

Schematic code follows:

CREATE PROCEDURE ABC

AS

BEGIN

    <query 1> ;

    <query 2> ;

    <query 3> ;

    <query 4> ;

    <query 5> ;
    :
    :
END ;

Then:

EXEC ABC ;

Hope this helps.

You create a job in SQL Server Agent. You then have basically two options:

  • Put all the queries into a single script.
  • Put each query into a separate job step.

Or some combination of the two.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM