Я хочу преобразовать код цикла while из
BEGIN
BEGIN try
DECLARE @r varchar(max)
PRINT 'Moving from Id ' + CAST(@FromID AS VARCHAR) + ' , '+ CAST(@ToID AS VARCHAR)
SET @cnt = @cnt+1
PRINT 'Now processing record no '+CAST(@cnt AS VARCHAR)
EXEC dbo.spadMergeIndividuals @FromID,@ToID, @r OUTPUT
END try
BEGIN CATCH
INSERT INTO @error(ErrorCode, FromID,ToID,TransactionState,ErrorMessage)
SELECT ERROR_NUMBER(),@FromID,@ToID, XACT_STATE(), ERROR_MESSAGE()
END CATCH;
FETCH NEXT FROM C INTO @NewId, @FromID,@ToID
END
в
SELECT @ii=MIN(Code_ID),@iiMax=MAX(Code_ID) FROM @TemporaryStagingTable
WHILE @ii<=@iiMax
BEGIN
BEGIN try
DECLARE @r varchar(max)
PRINT 'Moving from Id ' + CAST(@FromID AS VARCHAR) + ' , '+ CAST(@ToID AS VARCHAR)
SET @cnt = @cnt+1
PRINT 'Now processing record no '+CAST(@cnt AS VARCHAR)
EXEC dbo.spadMergeIndividuals @FromID,@ToID OUTPUT
END try
BEGIN CATCH
INSERT INTO @error(ErrorCode, FromID,ToID,TransactionState,ErrorMessage)
SELECT ERROR_NUMBER(),@FromID,@ToID, XACT_STATE(), ERROR_MESSAGE()
END CATCH;
--PRINT @r
SELECT @ii=@ii+1
END
Моя проблема связана с EXEC dbo.spadMergeIndividuals @FromID,@ToID OUTPUT
Я хочу, чтобы выполнение ссылалось на переменные FromID и ToID в таблице @ TemporaryStagingTable ?