我有以下带有 SQL 查询的代码PreparedSentence:public final ProductInfoExt getProductInfoByCode(String sCode, String siteGuid) throws BasicException { if (sCode.startsWith("977")) { // This is an ISSN barcode (news and magazines) // the first 3 digits correspond to the 977 prefix assigned to serial publications, // the next 7 digits correspond to the ISSN of the publication // Anything after that is publisher dependant - we strip everything after // the 10th character sCode = sCode.substring(0, 10); } return (ProductInfoExt) new PreparedSentence(s, "SELECT " + getSelectFieldList() + " FROM STOCKCURRENT AS C RIGHT JOIN PRODUCTS P ON (C.PRODUCT = P.ID) " + " WHERE P.CODE OR (P.REFERENCE = ? ) AND C.SITEGUID = ? ", new SerializerWriteBasicExt(new Datas[]{Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING}, new int[]{0, 1}), ProductInfoExt.getSerializerRead()).find(sCode, siteGuid);}P.CODE如果我通过:进行搜索,效果会很好WHERE P.CODE = ? AND C.SITEGUID = ?。P.REFERENCE但是,假设我希望它在if 中没有匹配的情况下找到结果P.CODE。我尝试执行这样的代码语句,但没有成功:WHERE P.CODE OR P.REFERENCE = ? AND C.SITEGUID = ?,但收到错误。任何帮助将不胜感激。
2 回答
扬帆大鱼
TA贡献1799条经验 获得超9个赞
OR
将你的陈述分组
return (ProductInfoExt) new PreparedSentence(s, "SELECT " + getSelectFieldList() + " FROM STOCKCURRENT AS C RIGHT JOIN PRODUCTS P ON (C.PRODUCT = P.ID) " + " WHERE (P.CODE = ? OR P.REFERENCE = ?) AND C.SITEGUID = ? ", new SerializerWriteBasicExt(new Datas[]{Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING}, new int[]{0, 1, 2}), ProductInfoExt.getSerializerRead()).find(sCode, sCode, siteGuid);
繁星coding
TA贡献1797条经验 获得超4个赞
你的语法错误,应该是
WHERE (P.CODE = ? OR P.REFERENCE = ?) AND C.SITEGUID = ?
然后你需要设置第三个参数
添加回答
举报
0/150
提交
取消