/*
given a table bi_customer_actions
with a field bca_delete_flag of tinyint or bit
and a field bca_add_date of datetime
note: the *if 1=1* structure allows me to fold them and turn them on and off
*/
declare
@Nrows int = 1000
if 1=1 /* testing the inner select */
begin
select top (@Nrows) *
from bi_customer_actions
where bca_delete_flag = 1
order by bca_add_date
end
if 1=1 /* delete or update or select */
begin
--select bca.*
--update bca set bca_delete_flag = 0
delete bca
from (
select top (@Nrows) *
from bi_customer_actions
where bca_delete_flag = 1
order by bca_add_date
) as bca
end