wrap last price rebuild in transaction
This commit is contained in:
parent
31172e7e35
commit
34c811123a
@ -1,7 +1,11 @@
|
|||||||
CREATE OR ALTER PROCEDURE pricing.rebuild_lastprice
|
CREATE OR ALTER PROCEDURE pricing.rebuild_lastprice
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NOCOUNT ON;
|
SET NOCOUNT ON;
|
||||||
|
SET XACT_ABORT ON; -- auto-rollback on most errors
|
||||||
|
|
||||||
|
BEGIN TRY
|
||||||
|
BEGIN TRAN; -- start transaction
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Reset target tables
|
-- Reset target tables
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -247,4 +251,25 @@ SELECT
|
|||||||
FROM flag_json f
|
FROM flag_json f
|
||||||
FULL OUTER JOIN seg_json s
|
FULL OUTER JOIN seg_json s
|
||||||
ON f.customer = s.customer AND f.partgroup = s.partgroup;
|
ON f.customer = s.customer AND f.partgroup = s.partgroup;
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- Commit if everything succeeded
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
COMMIT TRAN;
|
||||||
|
END TRY
|
||||||
|
BEGIN CATCH
|
||||||
|
-- Ensure transaction is rolled back
|
||||||
|
IF XACT_STATE() <> 0
|
||||||
|
BEGIN
|
||||||
|
ROLLBACK TRAN;
|
||||||
|
END
|
||||||
|
|
||||||
|
-- Optional: cleanup temp table (temp table persists for session until proc end,
|
||||||
|
-- but explicit drop is helpful if you reuse names or want to free resources)
|
||||||
|
IF OBJECT_ID('tempdb..#flagged') IS NOT NULL
|
||||||
|
DROP TABLE #flagged;
|
||||||
|
|
||||||
|
-- Rethrow the original error to the caller
|
||||||
|
THROW;
|
||||||
|
END CATCH;
|
||||||
END;
|
END;
|
||||||
|
Loading…
Reference in New Issue
Block a user