Solved

STORED procedure paramters delete

Posted on 2011-03-17
1
321 Views
Last Modified: 2012-05-11
In the following stored procedure BOTH images get deleted regardless of what is passed in for @ImageType.

Why
USE [Store]
GO
/****** Object:  StoredProcedure [dbo].[spDeleteImage]    Script Date: 03/17/2011 14:59:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spDeleteImage]
	-- Add the parameters for the stored procedure here
	@Product_ID		int,
	@ImageType      varchar(5)

AS


	SET NOCOUNT ON;
		
	IF @ImageType = 'main' 
		
		BEGIN
		declare @Product_Image int
		SELECT @Product_Image = Product_Image FROM Products WHERE Product_ID= @Product_ID	
		
		UPDATE Products SET Product_Image = null WHERE Product_ID = @Product_Image
		DELETE FROM Images WHERE  Image_ID = @Product_Image
		
	END
	
	IF @ImageType = 'thumb' 
		
		BEGIN
		
		DECLARE @Product_Thumb int
		SELECT @Product_Thumb = Product_Thumb FROM Products WHERE Product_ID = @Product_ID
		UPDATE ProductS SET Product_Thumb = null WHERE Product_Thumb = @Product_ID	
		
		DELETE FROM Images WHERE  Image_ID = @Product_Thumb
		
	END

Open in new window

0
Comment
Question by:vbnetcoder
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35161214
that is not possible.
you properly have coded the IF with BEGIN / END , so you must be looking at the code in another procedure / database than where you are actually running it.
0

Featured Post

Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

Join & Write a Comment

I have been working as System Administrators since 2003. I recently started working as a FreeLancer and was amazed to find out that very few people are taking full advantage of their Windows Server Machines. Microsoft Windows Server comes with so…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…

760 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

18 Experts available now in Live!

Get 1:1 Help Now