Solved

Stored procedure not working

Posted on 2011-09-07
6
199 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL LINE CONTINUATION ISSUE 12 32
Email Notifications for SQL 2005 9 27
Attaching Database Failed ? 3 39
Query Help - MSSQL - Averages 5 25
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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 insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

786 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