CREATE PROCEDURE dbo.OnlineAddCustomerInfo @ReservationNumber INT, @FirstName VARCHAR(50), @LastName VARCHAR(50), @Address1 VARCHAR(50), @Address2 VARCHAR(50), @Address3 VARCHAR(50), @City VARCHAR(50),
@Phone VARCHAR(30), @Email VARCHAR(96),
@ErrorLevel INT OUTPUT AS
SET NOCOUNT ON
/*
    Created by Jacob Pedersen January 2004

    Changes: N/A

    NOTES: 	- 

*/

SET @ErrorLevel = 00

/*
  Error Levels:
  00 : No errors
  01 : Reservation not found
*/

DECLARE @ResFound TINYINT
SELECT @ResFound = COUNT (*) FROM ReservationMain WITH (NOLOCK) WHERE ReferenceNumber=@ReservationNumber
IF @ResFound = 0
BEGIN
  SET @ErrorLevel = 01
  RETURN
END

-- test --
--SELECT * FROM ReservationAddress (NOLOCK) WHERE AddressType=1 AND AddressNumber IN (SELECT AddressNumber FROM ReservationAddressXTab (NOLOCK) WHERE ReferenceNumber=@ReservationNumber AND GuestNumber=0)  -- Online bookings are always single

UPDATE ReservationAddress SET
  FirstName=@FirstName,
  LastName=@LastName,
  Address1=@Address1,
  Address2=@Address2,
  Address3=@Address3,
  City=@City,
  Phone=@Phone,
  Email=@Email
WHERE AddressType=1 AND AddressNumber IN (SELECT AddressNumber FROM ReservationAddressXTab WITH (NOLOCK) WHERE ReferenceNumber=@ReservationNumber AND GuestNumber=0)  -- Online bookings are always single

-- test --
--SELECT * FROM ReservationAddress (NOLOCK) WHERE AddressType=1 AND AddressNumber IN (SELECT AddressNumber FROM ReservationAddressXTab (NOLOCK) WHERE ReferenceNumber=@ReservationNumber AND GuestNumber=0)  -- Online bookings are always single


