Kill SQL SPIDs for a certain SPID range, or a Date Range

  • Hello Everyone

    Is there a way to kill SPIDs in a certain SPID range? like all spids 75-100 etc... Or with a date range? Say all SPIDs that are over a day old? I am seeing some stale connections that are not closing.

    Thanks

    Andrew SQLDBA

  • I would create a simple function or just throw the results into a parameter table and loop through the spids, executing a kill command for each (you could also use a cursor). you could play with the query below to ensure you only get the spids you truly want to KILL...

    SELECT spid FROM sys. sysprocesses P

    JOIN sys .sysdatabases D ON (D .dbid = P. dbid)

    WHERE LTRIM (RTRIM( D.Name )) = @dbname

    AND P. spid != @@SPID

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply