Solved

STORED procedure paramters delete

Posted on 2011-03-17
1
330 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

To effectively work with Diskpart on a Server Core, it is necessary to write some small batch script's, because you can't execute diskpart in a remote powershell session. To get startet, place the Diskpart batch script's into a share on your loca…
If you migrate a Terminal Server licenses server inside the 2008 server family, you can takte advantage of the build-in migration tool. If you like to migrate an older 2003 Server (and the installed client CALs) to a 2008 R2 server for example, you …
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 give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…

895 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

13 Experts available now in Live!

Get 1:1 Help Now