You could use "output" of the update statement to receive the row id of the columns you have just updated and write this data into a temporary table or table variable.
This then allows more statements to be used to process the logging activity.
You could also consider using on update triggers on your table that perform the logging when your status changes.
use [tempdb];
go
create table [outputexample]
(
[rowid] int identity(1,1)
, [datetime] datetime default (getdate()) not null
, [status] varchar(20) not null
);
insert into [outputexample] ([status])
select 'Active' union all
select 'Closed' union all
select 'Active'
go
Scheduled job code:
declare @updatedrow table
(
[rowid] int
);
update [outputexample]
set [datetime] = getdate()
, [status] = 'Closed'
output inserted.[rowid]
into @updatedrow
where [datetime] < getdate()
and [status] <> 'Closed';
declare @rowid int;
declare cursor_updatedrow cursor for
select [rowid] from @updatedrow;
open cursor_updatedrow;
fetch next from cursor_updatedrow into @rowid;
while @@fetch_status = 0
begin
-- exec sp_myauditsp @rowid = @rowid
print cast(@rowid as varchar(20)) + ' was updated to closed.'
fetch next from cursor_updatedrow into @rowid;
end
close cursor_updatedrow;
deallocate cursor_updatedrow;