CREATE FUNCTION DBO.IsDepartmentInWareGrpList(@ADepartmentString VARCHAR (37), @AWareGroupNumberList VARCHAR (1000))
RETURNS BIT
AS
BEGIN
  DECLARE @CurrentDepartment VARCHAR (1)
  DECLARE @Idx INT
  DECLARE @Return BIT

  SET @Return = 0

  SET @Idx = 1
  WHILE @Idx < = LEN(@ADepartmentString) 
  BEGIN
    SET @CurrentDepartment  = SUBSTRING( @ADepartmentString, @Idx, 1)

    IF CHARINDEX (CONVERT(VARCHAR (1),@CurrentDepartment), @AWareGroupNumberList) > 0
    BEGIN
      SET @Return = 1
      BREAK       
    END

    SET @Idx = @Idx + 1
  END

  RETURN @Return
 
END

