Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

SQL Express Delete sproc problem


  • Please log in to reply
No replies to this topic

#1 hispaladin

hispaladin

  • Members
  • 245 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Middle of a corn field
  • Local time:03:01 AM

Posted 07 February 2014 - 12:32 PM

Ok here is my issue.  I have a database (very small) that stores asset data in one table and stores location codes in another, make codes in one and category codes in one.  I have it set this way so that the asset table only has to store the integer for the location, make, and category rather than the full text names.  The stored procedure I am trying to write is supposed to check to see if the category in the category table is in use in the asset table and if it is not, delete it and return (select) a value of 0, and if the value does exist in the asset table select a value of 1.  The sproc more or less does work except that it will not select the correct value so my website code cannot work correctly because it is not getting handed the right returned value.  here is my SQL code

ALTER PROCEDURE [dbo].[AssetManager_AddCategory]
	
	@Category nvarchar(50)

AS
if not exists (select @Category from dbo.CategoryCode where Category = @Category)
begin
INSERT INTO dbo.[CategoryCode]
	([Category])

	VALUES
	(@Category)

select 0
end

else
begin
select 1
end

The code will not delete an entry that is in use and will delete an entry that is not in use it just will not return the correct value.

Any ideas what I am doing wrong here?

 



BC AdBot (Login to Remove)

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users