CREATE FUNCTION dbo.GetOnlineBookTypeLinks (@AOnlineBookTypeNumber INT, @AGetKeys BIT)  
/*  
  Created by: Anders Vindal 20070921
*/
RETURNS VARCHAR(200) AS  
BEGIN 
  DECLARE  @Result VARCHAR (200)
  SET @Result = ''

  DECLARE @Name VARCHAR(20)
  DECLARE @OnlineBookTypeNumber INT

  DECLARE db_cur CURSOR READ_ONLY FAST_FORWARD FOR
    SELECT OnlineBookType.Name, OnlineBookTypeXTab.OnlineBookTypeLinkNumber
    FROM OnlineBookType WITH (NOLOCK)
    INNER JOIN OnlineBookTypeXTab  WITH (NOLOCK) ON OnlineBookType.OnlineBookTypeNumber =  OnlineBookTypeXTab.OnlineBookTypeLinkNumber 
      AND OnlineBookTypeXTab.OnlineBookTypeNumber = @AOnlineBookTypeNumber 
  OPEN db_cur

  FETCH NEXT FROM db_cur INTO @Name, @OnlineBookTypeNumber
  
  WHILE @@FETCH_STATUS = 0
  BEGIN
    IF @Result <> ''
      SET @Result = @Result + ','

    IF @AGetKeys = 1
      SET @Result = @Result + CONVERT(VARCHAR(3),@OnlineBookTypeNumber)
    ELSE
      SET @Result = @Result + @Name

    FETCH NEXT FROM db_cur INTO @Name, @OnlineBookTypeNumber
  END

  RETURN @Result
END

