473,385 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

sp_executesql question

I am trying to use the Kill command dynamically in a scheduled job. I have built a small script that does the following:

SET @ParmDefinition = N'@pid smallint'

-- load up SQLString once
SET @SQLString = N'KILL @pid'

..................

-- kill the process
EXECUTE sp_executesql @SQLString, @ParmDefinition, @pid = @spSpid

Note, @spSpid (smallint as well) is loaded up in a cursor that selects problem processes that need to be killed. I cannot get this to work. Am i missing something or is this unpossible? Thanks in advance.
May 23 '06 #1
1 1629
Hi,

Unfortunately KILL command can not be used this way. KILL is an exception in the syntax that you are trying to use.

But you can use KILL like below, declare variables once.

DECLARE @SQLString nvarchar(255)
DECLARE @SPID smallint

Then in the loop each time, you should run the below code statements

SET @SPID = 52
SET @SQLString = N'KILL ' + CAST(@SPID AS CHAR(5))
EXEC(@SQLString)
May 25 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cliverama | last post by:
help! fried brains.... asp calling a sqlserver7 stored proc which dynamically builds a sqlstatement & passes it to sp_executesql asp page gives the operation not allowed when object is closed...
1
by: Justin Wong | last post by:
CREATE PROCEDURE dbo.Synchronization_GetNewRecords ( @item varchar(50), @last datetime ) AS SET NOCOUNT ON
1
by: DBA | last post by:
Does anyone know the technical reason for why sp_executesql uses the N prefix before the string that is passed? For example: sp_executesql N'USE Northwind' Thanks!
3
by: thomson | last post by:
Hi all, Can sp_executesql used inside a user defined function, i tried but it has compiled well, but when i call the functio it shows Only functions and extended stored procedures can be executed...
1
by: LineVoltageHalogen | last post by:
Greetings All, currentley there is a heated discussion in my place of work over which method is better/more efficient for simple selects. Background: 1.) Simple Application that uses sql server...
7
by: LineVoltageHalogen | last post by:
Greetings All, I have a very large query that uses dynamic sql. The sql is very large and it requires it to be broken into three components to avoid the nvarchar(4000) issue: SET @v_SqlString(...
3
by: elRoyFlynn | last post by:
This is a odd problem where a bad plan was chosen again and again, but then not. Using the profiler, I identified an application-issued statement that performed poorly. It took this form: ...
1
by: Matik | last post by:
Hi to all, Probably I'm just doing something stupid, but I would like you to tell me that (if it is so), and point the solution. There ist the thing: I' having a sp, where I call other sp...
1
by: satishchandrat | last post by:
Hi, This is regarding the sp_executesql and the sql statement parameter, in processing a dynamic SQL on SQL Server 2000, in my stored procedure. I have my SQL string exeeding more than 4000...
5
by: Yash | last post by:
Hi, I am using SQL 2000 SP4. I have compared 2 scenarios: Scenario 1: insert into #bacs_report SELECT ..... WHERE <conditions>
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.