CREATE FUNCTION dbo.CustomerGeographics (@CustomerNumber INTEGER)
RETURNS VARCHAR(3840) AS
/*
    Made by JP because devexpress checkcombobox sucks.

*/
BEGIN 

  DECLARE
  @Text VARCHAR(30),
  @Result VARCHAR(3840)

  DECLARE geo_cursor CURSOR FOR

    SELECT TEXT FROM Geographic WITH (NOLOCK) INNER JOIN CustomerGeographic WITH (NOLOCK) ON Geographic.GeographicNumber = CustomerGeographic.GeographicNumber WHERE CustomerNumber=@CustomerNumber

  OPEN geo_cursor
  FETCH NEXT FROM geo_cursor INTO @Text

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

    SET @Result = @Result + @Text

    FETCH NEXT FROM geo_cursor INTO @Text
  END

  CLOSE geo_cursor
  DEALLOCATE geo_cursor

  RETURN @Result
END

