I have an update stored procedure that implements optimistic locking. The stored procedure looks like this:
ALTER PROCEDURE [dbo].[usp_Test]
@Id AS char(2),
@recordTimestamp as timestamp
...
BEGIN
UPDATE XY
..
WHERE ((Id = @Id) AND (recordTimeStamp = @recordTimestamp))
if @@rowcount = 0
begin
RAISERROR ('this row was changed by another user', 18, 1)
end
SELECT timeStamp from XY where Id = @Idend
Is there a simpler way to return the new timestamp? I would really like to avoid the SELECT statement.
Assuming at least SQL Server 2005 you can use
OUTPUTOr a version that uses a table variable to more closely mirror the behaviour of the original query.