Updating a record from a table and returning the updated record.
-
Hello. I am making a stored procedure with the following SQL statement: Update Table1 set Field1='X' Where Field2 = 'N' I want the StoredProcedure to return Field3 from the updated record. Is it possible to do this? Thanks.
sure right after your update, put the select statement select field3 from table1 where field2 = 'N' and execute your stored procedure with either cmd.ExecuteReader() / cmd.ExecuteScalar() daniero
-
sure right after your update, put the select statement select field3 from table1 where field2 = 'N' and execute your stored procedure with either cmd.ExecuteReader() / cmd.ExecuteScalar() daniero
Actually that's not exactly what I wanted. The example I gave was not complete. Here's what I want to do: - Select @Res = max(Y) From table1 where X=0 - Update table1 set X=1 where Y = @Res I want to get the max record where X=0 and then update that record. The problem is that there may be two processes executing this stored procedure at the same time. Thus, they may execute the 'select' part at the same time, get the same 'max(Y)' and then update the same record. That's what I wnat to avoid. I need to assure that between the 'select' and the 'update' there is no process accessing the same record in the table. This is a concurrency problem.