如果参数值为null,则查询返回所有记录

时间:2014-03-31 20:30:53

标签: mysql sql where isnull

SELECT g.date,g.description,g.amount AS cash,0 AS cheque FROM generalledger AS g WHERE g.type="cash" AND g.date=?
UNION ALL
SELECT gg.date,gg.description,0 AS cash, gg.amount AS cheque FROM generalledger AS gg WHERE gg.type="cheque" AND gg.date=?

我有这个查询我想检查g.date的& gg.date的参数值为null然后返回所有其他记录,只根据参数值返回记录。

1 个答案:

答案 0 :(得分:1)

尝试

AND (g.date=? or ? is null)