Hi @RJ,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
In addition to the above answer provided by Amira Bedhiafi
Is there a way to run SQL Statements in parallel within the same SP?
Yes, you can run SQL statements in parallel within the same stored procedure (SP) by using SQL Server Agent Jobs.
Here’s a basic example using SQL Server Agent Jobs:
Create a job for each independent task (e.g., CUST1 and CUST2).
Use sp_start_job to start the jobs from within your stored procedure.
Here’s how you can modify your stored procedure to run the tasks in parallel:
CREATE PROCEDURE CustomerPARALLEL
AS
BEGIN
-- Start Job for CUST1
EXEC msdb.dbo.sp_start_job @job_name = 'Job_CUST1';
-- Start Job for CUST2
EXEC msdb.dbo.sp_start_job @job_name = 'Job_CUST2';
END
For more information, please refer the document: https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-start-job-transact-sql?view=sql-server-ver16
Hope this helps. Do let us know if you have any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.