declare @spid
int,
@sqlstm
nvarchar(120)
DECLARE processes_cursor CURSOR
FOR
select spid
from
master.dbo.sysprocesses
where spid
>= 0 and spid <= 32767 and spid
<> @@spid and kpid
<> 0
and
spid in (select distinct blocked from master.dbo.sysprocesses where blocked <> 0)
OPEN processes_cursor
FETCH NEXT FROM processes_cursor
INTO @spid
WHILE @@FETCH_STATUS = 0
BEGIN
set
@sqlstm = 'kill '+CONVERT(varchar(3),
@spid)
exec
sp_executesql @sqlstm
FETCH NEXT FROM processes_cursor INTO @spid
END
CLOSE processes_cursor
DEALLOCATE processes_cursor