CREATE FUNCTION dbo.GetWareHallTypesString(@AWareNumber int, @GetKeys bit)

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

  IF @GetKeys = 0
  BEGIN 
    SELECT @Result =
    SUBSTRING(
    (
      SELECT ',' + CAST(ConferenceRoomTypes.Type AS VARCHAR(MAX))
      FROM ConferenceRoomTypes WITH (NOLOCK)
      INNER JOIN WareConferenceRoomtypesXtab WITH (NOLOCK) ON WareConferenceRoomtypesXtab.FK_ConferenceRoomtypeNumber =  ConferenceRoomTypes.ConferenceRoomTypeNumber AND
      WareConferenceRoomtypesXtab.FK_WareNumber = @AWareNumber 
      ORDER BY ConferenceRoomTypes.Type
      FOR XML PATH('')
    ),2,200000)
  END
  ELSE
  BEGIN
    SELECT @Result =
    SUBSTRING(
    (
      SELECT ',' + CAST(ConferenceRoomTypes.ConferenceRoomTypeNumber AS VARCHAR(MAX))
      FROM ConferenceRoomTypes WITH (NOLOCK)
      INNER JOIN WareConferenceRoomtypesXtab WITH (NOLOCK) ON WareConferenceRoomtypesXtab.FK_ConferenceRoomtypeNumber =  ConferenceRoomTypes.ConferenceRoomTypeNumber AND
      WareConferenceRoomtypesXtab.FK_WareNumber = @AWareNumber 
      ORDER BY ConferenceRoomTypes.Type
      FOR XML PATH('')
    ),2,200000)
  END

  RETURN @Result
end