Solved

Stored procedure not working

Posted on 2011-09-07
6
197 Views
Last Modified: 2012-05-12
Hello Experts,

My stored procedure is not working.  It's supposed to delete records in the specified tables but it's not doing anything.  I'm not getting any error.  There are no relationships.  Any ideas?

Thanks

ALTER PROCEDURE [dbo].[spDeleteNHID]
	-- Add the parameters for the stored procedure here
	@NHID varChar(50)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

DELETE FROM tblFacilities WHERE tblFacilities.nhid = '@NHID';
DELETE FROM tblFacilityInfo WHERE tblFacilityInfo.nhid = '@NHID';
DELETE FROM tblDataLogging WHERE tblDataLogging.nhid = '@NHID';
DELETE FROM tblMaterials WHERE tblMaterials.nhid = '@NHID';
DELETE FROM tblMileage WHERE tblMileage.nhid = '@NHID';
DELETE FROM tblToComplete WHERE tblToComplete.nhid = '@NHID';


END

Open in new window

0
Comment
Question by:eshurak
  • 3
  • 2
6 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 36497927
remove ' from your queries
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36497930
for example:

DELETE FROM tblFacilities WHERE tblFacilities.nhid = '@NHID';
-->
DELETE FROM tblFacilities WHERE tblFacilities.nhid = @NHID;
0
 
LVL 6

Expert Comment

by:effes
ID: 36497935
Hi,

try removing the quotes around the @NHID in the comparisons in your WHERE-Clauses. The way you're doing it compares the values in the fields to the string @NHID and not to the value stored in the variable.

Change lines 10-15 to:

DELETE FROM tblFacilities WHERE tblFacilities.nhid = @NHID;
DELETE FROM tblFacilityInfo WHERE tblFacilityInfo.nhid = @NHID;
DELETE FROM tblDataLogging WHERE tblDataLogging.nhid = @NHID;
DELETE FROM tblMaterials WHERE tblMaterials.nhid = @NHID;
DELETE FROM tblMileage WHERE tblMileage.nhid = @NHID;
DELETE FROM tblToComplete WHERE tblToComplete.nhid = @NHID;

Hope that helps,
Frank
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Expert Comment

by:effes
ID: 36497959
Oops! Too slow :)
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36498038
yes you are :) thats why I posted short answer ha ha...
0
 
LVL 3

Author Comment

by:eshurak
ID: 36498158
Thanks guys.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Query 34 80
Near realtime alert if SQL Server services stop. 20 53
T-SQL:  I Want "Summary"--Not "Detail" 6 20
Splitting the content of a column in SQL 11 20
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now