如果过程在下次插入2小时后出现错误等,我尝试编写一个先插入几小时行的过程:
此代码会覆盖ERROR_COUNT
。我必须如何声明为每次调用存储该值的变量@error_count
?
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[errorcount]
AS
BEGIN
DECLARE @Data DateTime
DECLARE @error_count int
SET @error_count = 0
-- if first run error_count = 0 --
SET @Data = DATEADD(HOUR, -1 * @error_count - 1, GETDATE())
BEGIN TRANSACTION
Select ... where Date > @Date
IF @@ERROR <> 0
BEGIN
ROLLBACK TRANSACTION
set @error_count= @error_count + 1;
END
ELSE begin
COMMIT TRANSACTION
set @error_count = 0
end
END
答案 0 :(得分:0)