title: SQL script to kill all blocked processes?
body: <p>I'm trying to create an SQL script that will kill all blocked process.</p>
  
  <p>Am I missing something? </p>
  
  <pre><code>declare @max_count int, @count int, @sqlstring varchar(100)
  declare @spid_table table (spid int NOT NULL)
  
  INSERT @spid_table
  select spid
  from master.dbo.sysprocesses
  where spid in (select blocked from master.dbo.sysprocesses where blocked &gt; 0) 
  
  select @max_count = MAX(spid) FROM @spid_table
  select top 1 @count = spid from @spid_table
  
  while @count &lt;= @max_count
  begin
  select @sqlstring = 'kill ' + CONVERT(varchar(4), @count)
  exec(@sqlstring)
  end
  </code></pre>