CREATE PROCEDURE [dbo].[OnlineGetTableBookingSeating] 
(
  @APax INT = 0, 
  @ADepartmentNumber char(1) = ''
)
AS
/*
MLJ/2025-04-16: Fixed problem with duplicates
SG/2021-10-11: OUTER JOIN instead of inner join
SG/2021-09-16: New optional parameter @ADepartmentNumber
LJE/20110921: Read MaxPax as TableSize.
LJE/20110803: Created.
*/
BEGIN
  select tbs.TotalPax 
   ,tbs.Priority
   ,tbs.TableCount
   ,crt.MaxPax TableSize
   ,tbs.PaxAtTable
   ,crt.Type 
   ,crt.ConferenceRoomTypeNumber ResourceId
   ,tbs.Description SeatingDescription
  from TableBookingSeating tbs (NOLOCK)
  inner join CONFERENCEROOMTYPES crt (NOLOCK) on crt.ConferenceRoomTypeNumber=tbs.ConferenceRoomTypeNumber
  where tbs.TotalPax = @APax
  and tbs.Enabled = 1
  and (@ADepartmentNumber = '' or EXISTS(select * from TableTypeDepXtab ttx (NOLOCK) where ttx.TableTypeNumber=crt.ConferenceRoomTypeNumber and ttx.DepartmentNumber = @ADepartmentNumber ) )
  order by tbs.Priority,crt.Type
END
