请问事务这样写对不对呢
DECLARE @ErrorSum int
SET @ErrorSum = 0
BEGIN TRAN
UPDATE XXXXXXXXXXXXXXXXXX
SET @ErrorSum=@ErrorSum+@@ERROR
UPDATE XXXXXXXXXXXXXXXXXX
SET @ErrorSum=@ErrorSum+@@ERROR
UPDATE XXXXXXXXXXXXXXXXXX
SET @ErrorSum=@ErrorSum+@@ERROR
IF (@ErrorSum<>0)
BEGIN
ROLLBACK TRAN
RETURN 0
END
ELSE
BEGIN
COMMIT TRAN
RETURN 1
END
------解决方案-------------------- BEGIN TRANSACTION
BEGIN TRY
UPDATE CampaignCust
SET SaleNo = C.SaleNo
FROM CampaignCust A
INNER JOIN CampaignOffer B WITH(NOLOCK)
ON A.CampaignID = B.CampaignID and A.BrandCode = B.BrandCode and A.OfferID = B.OfferID
INNER JOIN SaleCoupon C WITH(NOLOCK)
ON A.BrandCode = C.BrandCode AND A.CouponNO = C.CouponNo
WHERE C.SaleNo IS NOT NULL
AND C.ModiDateTime > CAST(DATEADD(DD, -2, CAST(GETDATE() AS DATE)) AS DATETIME)