Question : deleting in batches,using rowcount

SET ROWCOUNT 1000
WHILE (1=1) BEGIN
   BEGIN TRANSACTION
Delete from tab1
where tdate <= convert(char(10),getdate(),101)

         IF @@ROWCOUNT = 0
   BEGIN
    COMMIT TRANSACTION
    BREAK
   END
   COMMIT TRANSACTION
END
 
i will have to modify this code but i am not sure where to.....

There are about 1967146 rows i will have to delete in chunks so that it doesn't fill up the log

Answer : deleting in batches,using rowcount

no need for the transaction as every sql statement is atomic.

set rowcount 1000
select 1
while @@rowcount > 0
         Delete tab1 where tdate <= convert(char(10),getdate(),101)
set rowcount 0

Random Solutions  
 
programming4us programming4us