Solved

Stored procedure not working

Posted on 2011-09-07
6
195 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

706 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

21 Experts available now in Live!

Get 1:1 Help Now