CREATE FUNCTION dbo.GetWareRoomTypeString(@AWareNumber  int, @GetKeys bit)
--Created AV 2008 0514

/*
  The function is used in Management --->> WareGroups- ->> Wares -- >>Advanced -->>Room  types

*/

RETURNS VARCHAR(8000)
AS
BEGIN

  DECLARE  @Result VARCHAR (8000)
  DECLARE  @Text Varchar (5)
  DECLARE  @PK_RoomTypeNumber int

  DECLARE Ware_cursor CURSOR FOR

  SELECT RoomTypes.Type, RoomTypes.RoomTypeNumber FROM RoomTypes WITH (NOLOCK)
  INNER JOIN WareRoomTypeXtab WITH (NOLOCK) ON WareRoomTypeXtab.FK_RoomTypeNumber =  RoomTypes.RoomTypeNumber AND
  WareRoomTypeXtab.FK_WareNumber = @AWareNumber 
  ORDER BY RoomTypes.Type

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

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

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

    FETCH NEXT FROM Ware_cursor INTO @Text, @PK_RoomTypeNumber
  END

  CLOSE Ware_cursor
  DEALLOCATE Ware_cursor

  RETURN @Result

end
