CREATE FUNCTION dbo.GetWareKeycardAddonString(@AWareNumber  int)
/* The function is used in Management --->> WareGroups- ->> Wares -- >>Advanced -->>Keycard Addon */

RETURNS VARCHAR(8000)
AS
BEGIN
  DECLARE  @Result VARCHAR (8000)
  DECLARE  @Text Varchar (70)

  DECLARE  Ware_cursor CURSOR FOR
  SELECT WareIntKeyCardAddonsXtab.KeyCardDescription FROM WareIntKeyCardAddonsXtab WITH (NOLOCK)
  WHERE WareIntKeyCardAddonsXtab.FK_WareNumber = @AWareNumber
  
  OPEN Ware_cursor
  FETCH NEXT FROM Ware_cursor INTO @Text

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

    SET @Result = @Result + @Text

    FETCH NEXT FROM Ware_cursor INTO @Text
  END

  CLOSE Ware_cursor
  DEALLOCATE Ware_cursor

  RETURN @Result
END
