-- Collection of code snippets by Arne Vajhøj 
-- posted to eksperten.dk, usenet and other places (2002-now) 
DELIMITER //
CREATE PROCEDURE vararg(_a1 VARCHAR(50), _a2 VARCHAR(50), _a3 VARCHAR(50))
BEGIN
    SELECT * FROM t1 WHERE f2 LIKE IFNULL(_a1,f2) AND f2 LIKE IFNULL(_a2,f2) AND f2 LIKE IFNULL(_a3,f2);
END//
DELIMITER ;

CALL vararg('%B%',NULL,NULL);
CALL vararg('%B%','B%',NULL);
CALL vararg('%B%','B%','%B');

DROP PROCEDURE vararg;
