Hi @kkran ,
Please refer below and check whether it is helpful.
create table letter
(
LetterId int,
ActiveInactiveInd varchar(10),
StoredProcforletter varchar(100)
)
insert into letter values
(1,'A','dbo.usp_ChildProcedure_001'),
(2,'A','dbo.usp_ChildProcedure_002'),
(3,'A','dbo.usp_ChildProcedure_003'),
(4,'A','dbo.usp_ChildProcedure_004'),
(5,'A','dbo.usp_ChildProcedure_005'),
(6,'I','dbo.usp_ChildProcedure_006'),
(7,'A','dbo.usp_ChildProcedure_007'),
(10,'A','dbo.usp_ChildProcedure_010'),
(11,'I','dbo.usp_ChildProcedure_011'),
(12,'A','dbo.usp_ChildProcedure_012'),
(13,'A','dbo.usp_ChildProcedure_013'),
(25,'I','dbo.usp_ChildProcedure_025')
SQL Server 2016 and before:
Create Procedure [dbo].[usp_MainProcedure]
@ActiveInactiveInd varchar(10)
AS
begin
declare @sql nvarchar(max)
SELECT @sql=STRING_AGG(CONCAT('EXEC ',StoredProcforletter ), CHAR(13))
FROM letter
where ActiveInactiveInd = @ActiveInactiveInd
--print @sql
EXECUTE sp_executesql @sql
End
exec [dbo].[usp_MainProcedure] 'A'
SQL Server 2017 and after:
Create Procedure [dbo].[usp_MainProcedure]
@ActiveInactiveInd varchar(10)
AS
begin
declare @sql nvarchar(max)
SELECT @sql=(
SELECT 'EXEC ' + StoredProcforletter +' '
FROM letter
FOR XML PATH(''))
FROM letter
where ActiveInactiveInd = @ActiveInactiveInd
--print @sql
EXECUTE sp_executesql @sql
End
exec [dbo].[usp_MainProcedure] 'A'
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues October--Users always get connection timeout problem when using multi subnet AG via listener. Especially after failover to another subnet