CREATE FUNCTION DBO.DepartmentFound (@ADepartmentSubString VARCHAR (37),@ADepartmentString VARCHAR (37))
RETURNS CHAR(1) AS
/*
Anders Vindal
*/
BEGIN
  DECLARE @Return CHAR(1)
  SET @Return = ''
  DECLARE @Idx INT

  SET @Idx = 1
  WHILE @Idx < = LEN(@ADepartmentSubString) 
  BEGIN
    IF CHARINDEX(SUBSTRING( @ADepartmentSubString, @Idx, 1), @AdepartmentString) > 0
    BEGIN
      SET @Return = SUBSTRING( @ADepartmentSubString, @Idx, 1)
      BREAK -- while
    END
    SET @Idx = @Idx + 1
  END

  RETURN @Return
END

