CREATE PROCEDURE [dbo].[OnlineFindParticipants] @AReferencenumber INT, @RoomLineNumber INT = 0 AS
SET NOCOUNT ON
/*
    	Created by Troels Buch November 2014

    	Changes: N/A
    	SG 2015-06-24: RoomLineNumber added as parameter, guestnumber added in result, subselelect changed to inner join.
    	TBU20141210: Added more fields
		TBU20141126: Added With (nolock)
		
    	NOTES: 	When @RoomLineNumber = 0 all names are returned

*/

select IsNull(FIRSTNAME, '') AS Firstname, IsNull(LASTNAME, '') AS Lastname, IsNull(ADDRESS3, '') AS CompanyName, ADDRESS1, ZIPCODE, CITY, PHONE, EMAIL,
       remX.GuestNumber 
from RESERVATIONADDRESS resa with (nolock)
inner join RESERVATIONADDRESSXTAB resax with (nolock) on resax.ADDRESSNUMBER = resa.AddressNumber
inner join RESERVATIONS res with (nolock) on resax.REFERENCENUMBER = res.ReferenceNumber
inner join ReservationMeetingXTab remX with (nolock) on remX.ReferenceNumber = resax.ReferenceNumber 
                                                    and (remX.ReservationConfLineNumber = @RoomLineNumber or @RoomLineNumber = 0)
where res.ReferenceNumber = @AReferencenumber
and remX.GuestNumber = resax.GUESTNUMBER
and res.GUESTNUMBER = 1
and AddressTypeNumber = 1
and resax.GUESTNUMBER > 0
