Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I tried to execute the following jo

Status
Not open for further replies.

fogal

Technical User
Aug 20, 2001
87
US
I tried to execute the following job, but it failed. It kills processes older than one day, that are non system user processes.

All ideas welcome.

declare @spid int, @sql varchar(1000)
select @spid = 10
while exists (select * from master..sysprocesses where spid > @spid and login_time > dateadd(dd,-1,getdate()))
begin
select @spid = min(spid) from master..sysprocesses where spid > @spid and login_time > dateadd(dd,-1,getdate())
select @sql = 'kill ' + convert(varchar(20),@spid)
exec (@sql)
end
 
Fails or just doesn't do what you think it should?

I'm thinking it should be:

login_time < dateadd(dd,-1,getdate())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top