Solved

Stored procedure not working

Posted on 2011-09-07
6
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 53

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 total points
ID: 36497927
remove ' from your queries
0
 
LVL 53

Expert Comment

by:Huseyin KAHRAMAN
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 6

Expert Comment

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

Expert Comment

by:Huseyin KAHRAMAN
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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…

739 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