Go4Expert

Go4Expert (http://www.go4expert.com/)
-   SQL Server (http://www.go4expert.com/forums/sql-server-forum/)
-   -   Stored procedure for retrieving and update existing records (http://www.go4expert.com/forums/stored-procedure-retrieving-update-t24891/)

becky.b 8Feb2011 11:36

Stored procedure for retrieving and update existing records
 
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:
Code:


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!

sql-programs 16Aug2011 18:21

Re: Stored procedure for retrieving and update existing records
 
Hi,

If u retrieve the previously entered records use the
SELECT IDENT_CURRENT(‘table name’)
is used the last inserted record id value from particular table.After that u can update the particular record with new values.

sql-programs 19Jul2013 16:17

Re: Stored procedure for retrieving and update existing records
 
ALTER PROCEDURE [OS].[UPDATE_ItmsRecords]
@itemName varchar(100),
@itemDesc varchar(1000),
@itemCat varchar(100)
AS

DECLARE @Validate Varchar(200)
SET @Validate=(Select itemName = @itemName WHERE itemName = @itemName)
IF(@Validate <> '')
UPDATE OS.Items SET itemName = @itemName , itemDesc = @itemDesc, itemCat = @itemCat WHERE itemName =
@itemName
ELSE
PRINT 'No Records'


Just You try it. I think it may be work properly


All times are GMT +5.5. The time now is 19:28.