Hi, I am using MS SQL Server 2008 to create a stored procedure that is responsible for retrieving and updating existing record from database. However, it does not update the records. I am not sure of what is wrong with the stored procedure.
This is the stored procedure that I have input:
ALTER PROCEDURE [OS].[UPDATE_ItemsRecords]
@itemID varchar(10),
@itemName varchar(1000),
@itemDesc varchar(10)
AS
Select @itemName = itemName, @itemDesc
= itemDesc from OS.Items
WHERE itemID = @itemID
UPDATE
OS.Items SET itemName = @itemName , itemDesc = @itemDesc WHERE itemID =
@itemID
|
I am unable to retrive and update the existing records. How do I resolve it?Thks!
Becky BloomwoodPosted Feb 8, 2011, 5:48 PM
Becky BloomwoodPosted Feb 8, 2011, 5:46 PM
ALTER PROCEDURE [OS].[UPDATE_ItemsRecords]
@itemID varchar(10),
@itemName varchar(1000),
@itemDesc varchar(10)
AS
UPDATE OS.Items SET itemName = @itemName , itemDesc = @itemDesc WHERE itemID = @itemID
I have modify to become the one that you guys suggested but the records still remains the same. Thanks!
Suthish NairPosted Feb 8, 2011, 2:49 PM
UPDATE OS.Items SET itemName = @itemName , itemDesc = @itemDesc WHERE itemID = @itemID
why you need a select query. what kind of logic you want to apply.
you want to retrive history records or something else.
provide more information, so we can help.
Micke BlomqvistPosted Feb 8, 2011, 12:09 PM
Select itemName, itemDesc from OS.Items WHERE itemID = @itemID
Replacing @itemID with the same parameter as from your C# code, do you get a hit on an item?
(Perhaps you need to trim your variable, taking away spaces???)
Becky BloomwoodPosted Feb 8, 2011, 10:38 AM
Micke BlomqvistPosted Feb 8, 2011, 9:53 AM
Just as Krishna says, you are just replacing the the existing values. Try to comment the select clause just running the update part.
The select clause is what is giving you a hard time!
Becky BloomwoodPosted Feb 8, 2011, 7:59 AM
Krishna GaradPosted Feb 8, 2011, 7:48 AM