我有一个正在尝试插入的 While 循环。
DECLARE @CurrentOffer int =121
DECLARE @OldestOffer int = 115
DECLARE @MinClubcardID bigint=0
DECLARE @MaxClubcardID bigint=1000
WHILE 1 = 1
BEGIN
INSERT INTO Temp WITH (TABLOCK)
SELECT top (100) clubcard from TempClub with (nolock) where ID between
@MinClubcardand and @MaxClubcard
declare @sql varchar (8000)
while @OldestOffer <= @CurrentOffer
begin
print @CurrentOffer
print @OldestOffer
set @sql = 'delete from Temp where Clubcard
in (select Clubcard from ClubTransaction_'+convert(varchar,@CurrentOffer)+' with (nolock))'
print (@sql)
exec (@sql)
SET @CurrentOffer = @CurrentOffer-1
IF @OldestOffer = @CurrentOffer
begin
-- my logic
end
end
end
我的 TempClub 表总是只检查前 100 条记录。我的 TempClub 表有 3000 条记录。我需要使用 ClubTransaction_121,ClubTransaction_120,ClubTransaction_119 表检查我所有的俱乐部卡所有 3000 条记录。