generate filter SQL string