1

就我而言,只有前 2 个参数是必需的。当用户没有给出其余参数时,我在 LIKE 语句中使用字符“%”,以便显示所有数据。知道如何为 IN 语句解决这个问题吗?解决方案参数 IN ('%') 不起作用 => Null

参数:
java.sql.Timestamp、java.sql.Timestamp、java.lang.String、java.lang.String、java.lang.String、java.lang.String

询问:

SELECT * 
FROM RC_Recall t INNER JOIN RC_RECALLSTORE s ON t.ID = s.RECALLID
WHERE t.creationdate >= ?1 AND t.enddate <= ?2 AND  t.id LIKE ?3 
      AND t.afdeling IN (?4) AND s.storeid IN (?5)
ORDER BY ID DESC
4

2 回答 2

1

SQL 中的 IN 语句不能接受通配符。您必须在查询中添加 OR 才能使其正常工作...

select * 
from RC_Recall t INNER JOIN RC_RECALLSTORE s ON t.ID = s.RECALLID
where t.creationdate >= ?1 
AND t.enddate <= ?2 
AND t.id LIKE ?3 
AND ('%' = ?4 OR t.afdeling IN (?4))
AND ('%' = ?5 OR s.storeid IN (?5))
ORDER BY ID DESC

如果您使用参数位置来传递参数,则可能必须将其更改为

AND ('%' = ?4 OR t.afdeling IN (?5))
AND ('%' = ?6 OR s.storeid IN (?7))

希望有帮助

于 2014-12-16T14:15:11.267 回答
0

相当硬编码查询,您可以根据输入动态构建查询。即,无论存在哪个输入,都只在 where 子句中添加那些标准。

于 2014-12-16T14:18:10.200 回答