Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Kill command inside procedure.

Author  Topic 

bobanjayan
Yak Posting Veteran

67 Posts

Posted - 2004-04-23 : 09:00:30

Can I use kill <sid> inside a procedure code?
If possible, how?

scottpt
Posting Yak Master

186 Posts

Posted - 2004-04-23 : 10:02:16
set @sqlstr='KILL ' + @sid

exec (@sqlstr)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-04-23 : 10:16:21
Make sure you start another test spid in qa to test it out...


USE Northwind
GO

EXEC sp_who2
GO

CREATE PROC mySproc99
AS
BEGIN
DECLARE @SPID int, @cmd varchar(255)

CREATE TABLE #myTemp99 (
SPID int
, Status varchar(50)
, Login varchar(255)
, HostName varchar(50)
, BlkBy char(10)
, DBName varchar(255)
, Command varchar(50)
, CPUTime int
, DiskIO int
, LastBatch varchar(50)
, ProgramName varchar(50)
, SPID2 int
)

INSERT INTO #myTemp99 EXEC sp_Who2

SELECT @SPID = MAX(SPID) FROM #myTemp99 WHERE SPID > 50

SELECT @cmd = 'KILL ' + CONVERT(varchar(15),@SPID)
EXEC(@cmd)

DROP TABLE #myTemp99
END
GO

EXEC mySproc99
GO

EXEC sp_who2
GO

DROP PROC mySproc99
GO



Brett

8-)
Go to Top of Page
   

- Advertisement -