当我尝试为begin catch块中的变量赋值时。它说could not be evaluated
:
我想收集所有这些记录' ids并在流程结束时记录它们。
OPEN FilesCursor;
FETCH NEXT FROM FilesCursor INTO @recordId;
WHILE @@FETCH_STATUS = 0
BEGIN
BEGIN DISTRIBUTED TRANSACTION;
BEGIN TRY
SET XACT_ABORT ON;
SET @insertQuery = 'INSERT INTO '+ @remoteLinkedServerName +'.PatlatDB.dbo.TestTab...';
SET @updateQuery = '...';
EXECUTE(@insertQuery);
EXECUTE(@updateQuery);
SET XACT_ABORT OFF;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
SET @errorIds += ',' + CAST(@recordId AS VARCHAR);
SET @errorMessage += '|' + CAST((SELECT ERROR_MESSAGE()) AS VARCHAR);
END;
END CATCH
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
FETCH NEXT FROM FilesCursor INTO @recordId;
END;
CLOSE FilesCursor;
DEALLOCATE FilesCursor;