So, I've got this query that doesn't work as a function. Can someone tell me why?
Query:
Code:
    SET @ADDR_NUM = 5308;
    SET @ADDR_DIR = 'W';
    SET @ADDR_STR = '96th';
    SET @ADDR_TYPE = 'St';
    SET @ADDR_PDIR = '';

    SELECT `WD`
    FROM data.street_index
    WHERE `STREET` LIKE @ADDR_STR COLLATE utf8_unicode_ci
    AND @ADDR_NUM >= `LO_RANGE`
    AND @ADDR_NUM <= `HI_RANGE`
    AND `DIR` LIKE @ADDR_DIR COLLATE utf8_unicode_ci
    AND `TYPE` LIKE @ADDR_TYPE COLLATE utf8_unicode_ci
    AND `PDIR` LIKE @ADDR_PDIR COLLATE utf8_unicode_ci
    AND IF(@ADDR_NUM % 2 = 0, `EOB` LIKE 'E' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci, `EOB` LIKE 'O' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci);
Function:
Code:
CREATE DEFINER=`root`@`localhost` FUNCTION `GetDistrict`(ADDR_NUM INT(5), ADDR_DIR VARCHAR(1), ADDR_STR VARCHAR(128), ADDR_TYPE VARCHAR(3), ADDR_PDIR VARCHAR(1)) RETURNS int(1)
BEGIN
    DECLARE wd INT(1);
    
    SELECT `WD` INTO wd
    FROM data.street_index
    WHERE `STREET` LIKE ADDR_STR COLLATE utf8_unicode_ci
    AND `LO_RANGE` <= ADDR_NUM
    AND `HI_RANGE` >= ADDR_NUM
    AND `DIR` LIKE ADDR_DIR COLLATE utf8_unicode_ci
    AND `TYPE` LIKE ADDR_TYPE COLLATE utf8_unicode_ci
    AND `PDIR` LIKE ADDR_PDIR COLLATE utf8_unicode_ci
    AND IF(ADDR_NUM % 2 = 0, `EOB` LIKE 'E' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci, `EOB` LIKE 'O' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci);

RETURN wd;
END
Example Data:
Code:
PRECINCT | DIR | STREET   | TYPE | PDIR | CITY     | LO_RANGE | HI_RANGE | E/O/B | ZIP   | CG | LG | JD | CB | BR | WD
----------------------------------------------------------------------------------------------------------------------
46       | W   | 96TH     | ST   |      | OAK CITY | 5300     | 5318     | B     | 12345 | 3  | 36 | 4  | 11 | 1  | 3
46       | W   | 96TH     | ST   |      | OAK CITY | 5334     | 5568     | B     | 12345 | 3  | 36 | 4  | 11 | 1  | 3
21       | W   | 96TH     | ST   |      | OAK CITY | 6800     | 7148     | E     | 12345 | 3  | 31 | 4  | 6  | 1  | 1
Function Query:
Code:
select data.GetDistrict(5308, 'W', '96th', 'St', '') AS `DISTRICT`;
When I run the query, it returns '3'. That is correct.
When I run the function, it returns null.