Monday, March 19, 2012

Is it Possible to a KILL a Process when Process Id is dynamic?

Hi,
I would like to kill a process using the KILL Statement. But the
Process id is dynamic. How can I kill that process?
Example:
Declare @.spid Numeric
SELECT @.spid = spid FROM SPIDTBL
KILL @.spid
Is this possible? How can I do this?
Sevugan.Cuse the process name to determine the spid?
You won't get what you expect,
you get what you deserve, include lessons.
"Sevugan" <Sevugan@.discussions.microsoft.com> wrote in message news:5A855EF7-56B3-4C66-8EF5
-D51DFAEBEC90@.microsoft.com...
> Hi,
> I would like to kill a process using the KILL Statement. But the
> Process id is dynamic. How can I kill that process?
>
> Example:
> Declare @.spid Numeric
> SELECT @.spid = spid FROM SPIDTBL
> KILL @.spid
> Is this possible? How can I do this?
>
> Sevugan.C|||Hi
You have to use Dynamic SQL to do that.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Sevugan" wrote:

> Hi,
> I would like to kill a process using the KILL Statement. But the
> Process id is dynamic. How can I kill that process?
>
> Example:
> Declare @.spid Numeric
> SELECT @.spid = spid FROM SPIDTBL
> KILL @.spid
> Is this possible? How can I do this?
>
> Sevugan.C|||Hi,
DECLARE @.lngProcessId NUMERIC
DECLARE @.svSQL VARCHAR(1000)
SET lngProcessId = 51
SET @.svSQL = 'KILL ' + CONVERT(VARCHAR(10), @.lngProcessId)
--PRINT @.svSQL
EXEC @.svSQL
I have used like the above statements block.
I am executing this inside a stored procedure. I am getting an error like th
is
"Could not find stored procedure 'KILL 51'."
How can I resolve this?
Regards,
Sevugan.C
"Mike Epprecht (SQL MVP)" wrote:
> Hi
> You have to use Dynamic SQL to do that.
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
>
> "Sevugan" wrote:
>|||EXEC (@.svSQL)
If you EXECute a SQL string you have to enclose it in parenthesis, otherwise
it is treated as a procedure name.
Jacco Schalkwijk
SQL Server MVP
"Sevugan" <Sevugan@.discussions.microsoft.com> wrote in message
news:596AD9F2-78A3-4D50-BF89-13FA3F6E0802@.microsoft.com...
> Hi,
> DECLARE @.lngProcessId NUMERIC
> DECLARE @.svSQL VARCHAR(1000)
> SET lngProcessId = 51
> SET @.svSQL = 'KILL ' + CONVERT(VARCHAR(10), @.lngProcessId)
> --PRINT @.svSQL
> EXEC @.svSQL
> I have used like the above statements block.
> I am executing this inside a stored procedure. I am getting an error like
> this
> "Could not find stored procedure 'KILL 51'."
> How can I resolve this?
>
> Regards,
> Sevugan.C
>
> "Mike Epprecht (SQL MVP)" wrote:
>

No comments:

Post a Comment