Generate where clause dynamically