CREATE FUNCTION dbo.GetOnlineBookTypesForWare (@AWareNumber INT )  

--Created AV 20060711 used in OnlineDelivery in management ware.

RETURNS VARCHAR (100)
BEGIN 

  DECLARE @Return Varchar (200)
  DECLARE @Name VARCHAR (50)

  SET @Return = ''
  DECLARE OnlineCur CURSOR FORWARD_ONLY FOR
  SELECT Name FROM OnlineBookType WITH (NOLOCK)
  INNER JOIN OnlineBookTypeWareXTab WITH (NOLOCK) ON OnlineBookType.OnlineBookTypeNumber = OnlineBookTypeWareXTab.OnlineBookTypeNumber
  AND OnlineBookTypeWareXTab.WareNumber = @AWareNumber
  OPEN OnlineCur
  FETCH NEXT FROM OnlineCur  INTO @Name
  WHILE  (@@FETCH_STATUS <> -1)
  BEGIN
    IF @Return <> ''
      SET @Return = @Return + ','
    SET @Return = @Return + @Name
    FETCH NEXT FROM OnlineCur  INTO @Name
  END
  CLOSE OnlineCur
  DEALLOCATE OnlineCur
Return @Return

END

