EJBQL only works on a static number of parameters so you can't really do what you want in a standard way without restorting to
Java code. However, many vendor offer extensions to allow dynamic query creation in CMP for just these types of problems, check your Application Server's documentation.