Declare @from INT = 0;
Declare @to INT = 0;
select @from = [ZZDAT] from [AS4_SQ].[dbo].[SALZZ] where ZZNAM = 'SALZ1';
select @to = MAX(Z1001) from [AS4_SQ].[dbo].[SALZ1];
if @from < 1000101
BEGIN
SET @from = 1000101;
select @from,count(*) FROM [AS4_SQ].[dbo].[SALZ1] where [Z1001] < @from;
DELETE FROM [AS4_SQ].[dbo].[SALZ1] where [Z1001] < @from;
END;
if @to > 1251299
BEGIN
SET @to = 1251299;
select @to,count(*) FROM [AS4_SQ].[dbo].[SALZ1] where [Z1001] > @to;
DELETE FROM [AS4_SQ].[dbo].[SALZ1] where [Z1001] > @to;
END;
select @to = MAX(Z1001) from [AS4_SQ].[dbo].[SALZ1];
if @from > @to
BEGIN
SET @from = @to;
END;
select @from,@to;
Declare @rcdcnt INT = 0;
Declare @cnt INT = @from;
WHILE @cnt <= @to
BEGIN
select @rcdcnt=count(*) FROM [AS4_SQ].[dbo].[SALZ1] where [Z1001] = @cnt;
select @cnt,@rcdcnt;
if @rcdcnt > 0
BEGIN
DELETE FROM [AS4_SQ].[dbo].[SALZ1] where [Z1001] = @cnt;
DBCC SHRINKFILE (AS4_SQ_LOG, 1);
END;
SET @cnt = @cnt + 1;
END;
留言列表