Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored procedure for retrieving and update existi

Author  Topic 

becky.b
Starting Member

4 Posts

Posted - 2011-02-08 : 01:14:42
Hi, I am doing a update stored procedure that allows me to retrieve and update exisiting records from database. However, records entered previously cannot be retreived, hence unable to update it.

This is the code for it:
ALTER PROCEDURE [OS].[UPDATE_ItmsRecords] 
@itemName varchar(100),
@itemDesc varchar(1000),
@itemCat varchar(100)
AS

Select @itemName = itemName , @itemDesc = itemDesc, @itemCat = itemCat WHERE itemName = @itemName
UPDATE OS.Items SET itemName = @itemName , itemDesc = @itemDesc, itemCat = @itemCat WHERE itemName = @itemName


How do I resolve it such that it can retrieve previous record and update it to the database(MS SQL Server 2008)
Thanks!

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-02-08 : 02:57:12
What is the unique key in your table.

quote:

UPDATE OS.Items SET itemName = @itemName , itemDesc = @itemDesc, itemCat = @itemCat WHERE itemName = @itemName



In the above update statement you are using same "itemName = @itemName" for update as well as where clause

Can you post table structure of Items
Go to Top of Page

Ranjit.ileni
Posting Yak Master

183 Posts

Posted - 2011-02-08 : 03:12:47
quote:


Select @itemName = itemName , @itemDesc = itemDesc, @itemCat = itemCat WHERE itemName = @itemName




FROM clause missing

--Ranjit
Go to Top of Page
   

- Advertisement -