CREATE PROCEDURE dbo.UpdateReservationRegistrationCardFromTemporary
(
	   @ReferenceNumber int
      ,@GuestNumber smallint
)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @CompanyName varchar(50)
	DECLARE @LASTNAME varchar(50)
	DECLARE @FIRSTNAME varchar(50)
	DECLARE @ADDRESS1 varchar(100)
	DECLARE @ADDRESS2 varchar(100)
	DECLARE @ZIPCODE varchar(10)
	DECLARE @CITY varchar(50)
	DECLARE @COUNTRYCODE varchar(3)
	DECLARE @EMAIL varchar(150)
	DECLARE @PHONE varchar(255)
	DECLARE @DateOfBirth datetime
	DECLARE @PassPortNumber varchar(25)
	DECLARE @Note varchar(MAX)
	DECLARE @Found bit = 0

	SELECT @Found=1,@LASTNAME=LASTNAME,@FIRSTNAME=FIRSTNAME,@ADDRESS1=ADDRESS1,@ADDRESS2=ADDRESS2,@ZIPCODE=ZIPCODE,@CITY=CITY,@COUNTRYCODE=COUNTRYCODE,@EMAIL=EMAIL,@PHONE=PHONE,@DateOfBirth=DateOfBirth,@PassPortNumber=PassPortNumber,@CompanyName=CompanyName, @Note=Note
	FROM dbo.ReservationRegistrationCard
	WHERE ReferenceNumber=@ReferenceNumber AND GuestNumber=@GuestNumber

	IF @Found=1
		EXEC dbo.UpdateReservationRegistrationCard
			@ReferenceNumber 
			,@GuestNumber 
			,@CompanyName 
			,@LASTNAME 
			,@FIRSTNAME
			,@ADDRESS1 
			,@ADDRESS2 
			,@ZIPCODE 
			,@CITY 
			,@COUNTRYCODE 
			,@EMAIL 
			,@PHONE 
			,@DateOfBirth 
			,@PassPortNumber
			,'Registration card saved to reservation from temporary storage'
			,@Note
END
