BEGIN TRY
SET NOCOUNT ON
SET XACT_ABORT ON
BEGIN TRANSACTION
IF NOT EXISTS(SELECT 1 FROM dbo.tblProducts
WHERE intProductID = @intProductID)
BEGIN
SELECT 'Product does not exists' AS strMessage
Rollback TRan
RETURN
END
UPDATE dbo.tblProducts SET
curPrice = 10
WHERE
intProductID = @intProductID
SELECT 'Success' AS strMessage
COMMIT TRAN
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS strMessage
ROLLBACK TRANSACTION
END CATCH
Translate
Thursday, 12 June 2014
RETURN inside a transaction with TRY-CATCH block
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment