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)
  DECLARE  @Text Varchar (5)
  DECLARE  @PK_HallNumber int

  DECLARE Ware_cursor CURSOR FOR

  SELECT ConferenceRooms.Number, ConferenceRooms.ConferenceRoomNumber FROM ConferenceRooms WITH (NOLOCK)
  INNER JOIN WareHallXtab WITH (NOLOCK) ON WareHallXtab.FK_HallNumber =  ConferenceRooms.ConferenceRoomNumber AND
  WareHallXtab.FK_WareNumber = @AWareNumber 
  ORDER BY ConferenceRooms.Number

  OPEN Ware_cursor
  FETCH NEXT FROM Ware_cursor INTO @Text, @PK_HallNumber

  SET @Result = ''
  WHILE @@fetch_status = 0
  BEGIN
    IF @Result <> ''
      SET @Result = @Result + ','

   IF @GetKeys = 1
    SET @Result = @Result + CONVERT(VARCHAR(6),@PK_HallNumber)
   ELSE
    SET @Result = @Result + @Text

    FETCH NEXT FROM Ware_cursor INTO @Text, @PK_HallNumber
  END

  CLOSE Ware_cursor
  DEALLOCATE Ware_cursor

  RETURN @Result

end

