I have nine strings which either are a SQL query or just empty (“”), depending on the state of several checkboxes. I need to combine them in another string like
string OP = "AND";
string query = "select * from table where " + string1 + OP + string2 + OP + string3 + OP + ... + " order by ID;"
The problem is, in between of the strings, I need to have an AND or an OR. But if any of the strings are empty, it gives me a SQL error. SQL doesn’t understand something like
select * from table where AND a = "adsf" AND AND AND z = "fghj" AND order by ID;
it has to look like this:
select * from table where a = "adsf" AND z = "fghj" order by ID;
You can put the strings in an array, remove the empty strings, and combine them using
Join:And for framework 3.5 change to: