I am working on a Transaction using Repeatable Read Isolation Level. I want to incorporate both Try-Catch and an Error-handler features in this Transaction. When I run the code, I get an error message that : Msg 102, Level 15, State 1, Line 18 Incorrect syntax near 'BEGIN'. Msg 102, Level 15, State 1, Line 23 Incorrect syntax near '@errnum'.
How do I complete this Transaction successfully? OR What is the correct way to write this Transaction?
This is my work as at now:
CREATE PROCEDURE ItemFlow (@Name VARCHAR(50),
@aPrice MONEY,
@bPrice MONEY)
AS
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
GO
BEGIN TRAN
IF EXISTS (SELECT 1
FROM Cashier
WHERE Item = '@Item')
UPDATE Cashier
SET bPrice = '@bPrice',
aprice = '@aprice'
WHERE Item = '@Item'
ELSE
INSERT INTO Cashier
(Item, aPrice, bPrice)
VALUES ('@Item', '@aPrice', '@bPrice')
END
BEGIN TRY
EXECUTE ItemFlow
END TRY
BEGIN CATCH
@errnum = ERROR_NUMBER(),
@severity = ERROR_SEVERITY(),
@errstate = ERROR_STATE(),
@proc = ERROR_PROCEDURE(),
@line = ERROR_LINE(),
@message = ERROR_MESSAGE()
END CATCH