How DataAssist does this is to store the where part of the query in a variable. When you are setting the variable you can check on your '$newchannel' and '$newproduct' to see if they both have valid values, if so you would write the where portion of the query with an and, if not you should check to see which one has the valid value and write the where clause with only that value.