?
Solved

STORED procedure paramters delete

Posted on 2011-03-17
1
Medium Priority
?
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
I was supporting a handful of Windows 2008 (non-R2) 2 node clusters with shared quorum disks. Some had SQL 2008 installed and some were just a vendor application that we supported. For the purposes of this article it doesn’t really matter which so w…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Suggested Courses

801 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