Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

STORED procedure paramters delete

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

ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg 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