close
use AS4_SQ;

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;

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 shfm1969 的頭像
    shfm1969

    外星人找路回家

    shfm1969 發表在 痞客邦 留言(0) 人氣()