CREATE FUNCTION dbo.ElementCount (@String VARCHAR(8000), @Delimiter CHAR(1))
RETURNS SMALLINT AS
/*
  Function which returns the number of elements in a string seperated by specified delimiter.

  LOG:
  20060102 JP: Created

  NOTES:
  - 

*/
BEGIN 
  DECLARE
  @Count SMALLINT

  SET @String = @String + @Delimiter
  SET @Count = 0

  WHILE LEN(@String) > 0
  BEGIN
    SET @Count = @Count + 1
    SET @String = SUBSTRING (@String, CHARINDEX(@Delimiter, @String) + 1, LEN(@String))
  END

  RETURN @Count
END

