In our application when the record is fetched after selecting it SQL Server needs to update the record. It does so by changing the status(this is one of the column) from requested to completed
I am using SET XACT_ABORT ON
can I update the record just after selecting it?
ALTER PROCEDURE [dbo].[GetOrderExportJobForProcess]
AS
BEGIN
DECLARE @Msg VARCHAR(1000), @ErrSev INT, @count INT
BEGIN TRY
SET NOCOUNT ON
SET XACT_ABORT ON -- <==
BEGIN
SELECT TOP 1 JobId, ProfileId, AffinityId, TrackId, StoreId, Request, [Status], Note, CreatedOn, UpdatedOn,ReqVersion
FROM OrderExportJob WITH(NOLOCK)
WHERE IsActive = 1 AND [Status] = 'Requested'
ORDER BY CreatedOn DESC
END
END TRY
BEGIN CATCH
SET @ErrSev = Error_Severity()
SET @Msg = 'Error #' + Cast(Error_Number() AS VARCHAR(10)) + ' occured!' + CHAR(13) + Error_Message() + CHAR(13) + 'Severity: ' + Cast(Error_Severity() AS VARCHAR(10)) + ' ' + 'State: ' + Cast(Error_State() AS VARCHAR(10)) + CHAR(13) + 'In ' + CASE WHEN Error_Procedure() IS NULL THEN 'GetOrderExportJobForProcess' ELSE 'GetOrderExportJobForProcess' + Error_Procedure() END + ' ' + 'On Line: ' + Cast(Error_Line() AS VARCHAR(10))
RAISERROR (@Msg, @ErrSev, 1)
END CATCH
END