ID列でループを使用して、ステートメントを動的に実行できます
IF OBJECT_ID(N'dbo.XmlProc', N'P') IS NOT NULL DROP PROC dbo.XmlProc
GO
CREATE PROC dbo.XmlProc
@xmlParam xml,
@paramOUT int OUTPUT
AS
SELECT @paramOUT = @XmlParam.value('/param[1]', 'nvarchar(1)')
GO
IF OBJECT_ID(N'dbo.XmlProc2', N'P') IS NOT NULL DROP PROC dbo.XmlProc2
GO
CREATE PROC dbo.XmlProc2
@xmlParam xml,
@paramOUT int OUTPUT
AS
SELECT @paramOUT = @XmlParam.value('/param[1]', 'nvarchar(1)')
GO
IF OBJECT_ID(N'dbo.XmlProc3', N'P') IS NOT NULL DROP PROC dbo.XmlProc3
GO
CREATE PROC dbo.XmlProc3
@xmlParam xml,
@paramOUT int OUTPUT
AS
SELECT @paramOUT = @XmlParam.value('/param[1]', 'nvarchar(1)')
GO
IF OBJECT_ID(N'tempdb.dbo.#ExecuteThese') IS NOT NULL DROP TABLE dbo.#ExecuteThese
CREATE TABLE dbo.#ExecuteThese
(
Id int IDENTITY,
StoredProcedure nvarchar(100),
Parameter xml
)
INSERT dbo.#ExecuteThese
VALUES('dbo.XmlProc @param, @paramOUT OUTPUT', '<param>1</param>'),
('dbo.XmlProc2 @param, @paramOUT OUTPUT', '<param>2</param>'),
('dbo.XmlProc3 @param, @paramOUT OUTPUT', '<param>3</param>')
DECLARE @id int = 1,
@param xml,
@parmRET int,
@dml nvarchar(max)
WHILE (@id IS NOT NULL)
BEGIN
SELECT @dml = StoredProcedure, @param = Parameter
FROM dbo.#ExecuteThese
WHERE Id = @Id
EXEC sp_executesql @dml, N'@param xml, @paramOUT int OUTPUT', @param, @parmRET OUTPUT
SELECT @parmRET AS parmRET
SELECT @id = MIN(Id) FROM dbo.#ExecuteThese WHERE Id > @Id
END