CREATE FUNCTION dbo.GetWareHallString(@AWareNumber int, @GetKeys bit)
--Created AV 20061219

/*
  The function is used in Management --->> WareGroups- ->> Wares -- >>Advanced -->>Hall numbers

*/

RETURNS VARCHAR(8000)
AS
BEGIN
  DECLARE  @Result VARCHAR (8000)

  IF @GetKeys = 0
  BEGIN 
    SELECT @Result =
    SUBSTRING(
    (
      SELECT ',' + CAST(ConferenceRooms.Number AS VARCHAR(MAX))
      FROM ConferenceRooms WITH (NOLOCK)
      INNER JOIN WareHallXtab WITH (NOLOCK) ON WareHallXtab.FK_HallNumber =  ConferenceRooms.ConferenceRoomNumber AND
      WareHallXtab.FK_WareNumber = @AWareNumber 
      ORDER BY ConferenceRooms.Number
      FOR XML PATH('')
    ),2,200000)
  END
  ELSE
  BEGIN
    SELECT @Result =
    SUBSTRING(
    (
      SELECT ',' + CAST(ConferenceRooms.ConferenceRoomNumber AS VARCHAR(MAX))
      FROM ConferenceRooms WITH (NOLOCK)
      INNER JOIN WareHallXtab WITH (NOLOCK) ON WareHallXtab.FK_HallNumber =  ConferenceRooms.ConferenceRoomNumber AND
      WareHallXtab.FK_WareNumber = @AWareNumber 
      ORDER BY ConferenceRooms.Number
      FOR XML PATH('')
    ),2,200000)
  END

  RETURN @Result
end