Wednesday, October 31, 2012

Ms Sql Transation


CREATE PROCEDURE [dbo].[usp_savePurchaseDetails](
@customerId varchar(50),
@productId varchar(50),
@userName varchar(50),
@bomEmailId varchar(50),
@amazonId varchar(50),
@phoneNumber varchar(50),
@status smallint,
@firstName varchar(50),
@middleName varchar(50),
@lastName varchar(50),
@homeName varchar(50),
@street varchar(50),
@city varchar(50),
@state varchar(50),
@country varchar(50),
@zipCode varchar(50),
@mobile varchar(50),
@homePhone varchar(50)
)
AS
BEGIN
 BEGIN TRANSACTION
 INSERT INTO BomAmazonCustomers (customerId,productId,userName,bomEmailId,phoneNumber,amazonId,purchasedDate,status)
 VALUES (@customerId,@productId,@userName,@bomEmailId,@phoneNumber,@amazonId, GETDATE(),@status)
  IF @@ERROR = 0 
  BEGIN
   INSERT INTO bomAmazonCustomersAddress (bomEmailId,firstName,middleName,lastName,houseName,street,city,state,country,zipCode,mobile,homePhone)
   VALUES (@bomEmailId,@firstName,@middleName,@lastName,@homeName,@street,@city,@state,@country,@zipCode,@mobile,@homePhone)
    IF @@ERROR = 0 
     BEGIN
       COMMIT TRANSACTION
     END
    ELSE
   BEGIN
    ROLLBACK TRANSACTION
    RETURN
   END
  END
  ELSE
  BEGIN
   ROLLBACK TRANSACTION
   RETURN
  END
END

No comments:

Post a Comment