Code to generate where clause (untested)