CREATE PROCEDURE [dbo].[OnlineUpdateParticipants1] @Referencenumber INT
	,@RoomLineNumber INT = 0
	,@Firstname VARCHAR(50)
	,@Lastname VARCHAR(50)
	,@CompanyName VARCHAR(50)
	,@Fullname VARCHAR(100)
	,@Address VARCHAR(100)
	,@Zipcode VARCHAR(50)
	,@City VARCHAR(50)
	,@Phone VARCHAR(50)
	,@Email VARCHAR(100)
	,@Guestnumber INT
AS
SET NOCOUNT ON

/*
    Created by Troels Buch Nov 2014
    
    Changes:
    SG 2015-07-02: Build Empty namelist moved to OnlineUpdateParticipantsAll
    SG 2015-06-22: Added @RoomLineNumber as parameter
    TBU20150220: Added PaysAdults, PaysChildren, PaysChildren2
    TBU20141210: Changed UPDATE RESERVATIONADDRESS    

    NOTES: 	SG/2015-05-11: Called by OnlineUpdateParticipantsAll
*/
DECLARE @NumberOfParticipants INT
DECLARE @ConfLineNumber INT
DECLARE @HasNameList INT
DECLARE @AddressNumber INT
DECLARE @DefaultName VARCHAR(50)

-- Check Fullname
IF @Fullname <> ''
	SET @Lastname = @Fullname;

SELECT @ConfLineNumber = ReservationConfLineNumber
	,@NumberOfParticipants = Adults
FROM RESERVATIONCONFERENCELINE WITH (NOLOCK)
WHERE ReferenceNumber = @Referencenumber
	AND (
		ReservationConfLineNumber = @RoomLineNumber
		OR @RoomLineNumber = 0
		)

PRINT 'OnlineUpdateParticipants: Lastname=' + @Lastname + ', @Guestnumber=' + convert(CHAR(6), @Guestnumber)

SELECT @AddressNumber = ADDRESSNUMBER
FROM RESERVATIONS res WITH (NOLOCK)
INNER JOIN RESERVATIONADDRESSXTAB resax WITH (NOLOCK) ON resax.REFERENCENUMBER = res.ReferenceNumber
INNER JOIN ReservationMeetingXTab remX WITH (NOLOCK) ON remX.ReferenceNumber = resax.ReferenceNumber
	AND remX.ReservationConfLineNumber = @ConfLineNumber
WHERE res.ReferenceNumber = @Referencenumber
	AND remX.GuestNumber = resax.GUESTNUMBER
	AND res.GUESTNUMBER = 0
	AND AddressTypeNumber = 1
	AND resax.GUESTNUMBER = @Guestnumber

PRINT '@AddressNumber=' + convert(CHAR(6), @AddressNumber)

UPDATE RESERVATIONADDRESS
SET FIRSTNAME = @Firstname
	,LASTNAME = @Lastname
	,ADDRESS3 = @CompanyName
	,ADDRESS1 = @Address
	,ZIPCODE = @Zipcode
	,CITY = @City
	,PHONE = @Phone
	,EMAIL = @Email
WHERE AddressNumber = @AddressNumber

PRINT 'Efter UPDATE'
