By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create proc sp_indicators (@ids varchar(100)) as
begin
select @ids as id
end
CREATE PROCEDURE sp_indicators_multi
(
@IDS VARCHAR(MAX)
)
AS
BEGIN
DECLARE @sql NVARCHAR(MAX);
-- Split the input parameter into individual indicators
DECLARE @indicators TABLE (indicator VARCHAR(50));
INSERT INTO @indicators (indicator)
SELECT value FROM STRING_SPLIT(@IDS, ',');
-- Iterate through the indicators and execute sp_indicators for each one
DECLARE @indicator VARCHAR(50);
DECLARE cur CURSOR FOR SELECT indicator FROM @indicators;
OPEN cur;
FETCH NEXT FROM cur INTO @indicator;
WHILE @@FETCH_STATUS = 0
BEGIN
EXECUTE sp_indicators @indicator;
FETCH NEXT FROM cur INTO @indicator;
END;
CLOSE cur;
DEALLOCATE cur;
END;
EXECUTE sp_indicators_multi 'IDS001,IDS002,IDS015,IDS022';
id |
---|
IDS001 |
id |
---|
IDS002 |
id |
---|
IDS015 |
id |
---|
IDS022 |