Link to home
Start Free TrialLog in
Avatar of eshurak
eshurakFlag for United States of America

asked on

Stored procedure not working

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

ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for example:

DELETE FROM tblFacilities WHERE tblFacilities.nhid = '@NHID';
-->
DELETE FROM tblFacilities WHERE tblFacilities.nhid = @NHID;
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
Oops! Too slow :)
yes you are :) thats why I posted short answer ha ha...
Avatar of eshurak

ASKER

Thanks guys.