ict.ken.be

Delivering solid user friendly software solutions since the dawn of time.

Kill process

Categories: SQL Server


Declare @dbid int,
        @spid int,
        @str nvarchar(128)
select @dbid = dbid from master..sysdatabases
  where name = 'DB_MESSAGENT'
declare spidcurs cursor for
   select spid from master..sysprocesses where dbid = @dbid
open spidcurs
fetch next from spidcurs into @spid
While @@fetch_status = 0
  Begin
    Select @str = 'Kill '+ convert(nvarchar(30),@spid)
    --exec(@str)
    select @str
    fetch next from spidcurs into @spid
End
Deallocate spidcurs