我有九个字符串,它们要么是 SQL 查询,要么只是空的 (""),具体取决于几个复选框的状态。我需要将它们组合在另一个字符串中,例如
string OP = "AND";
string query = "select * from table where " + string1 + OP + string2 + OP + string3 + OP + ... + " order by ID;"
问题是,在字符串之间,我需要一个AND
或一个OR
. 但如果任何字符串为空,它会给我一个 SQL 错误。SQL不理解类似的东西
select * from table where AND a = "adsf" AND AND AND z = "fghj" AND order by ID;
它必须看起来像这样:
select * from table where a = "adsf" AND z = "fghj" order by ID;