我正在写一个采用单个日期时间参数的mysql存储过程。它使用它在一个select语句这样..MySQL可能的空值过滤
select *
from table
where date >= @datefrom or @datefrom is null
当我写T-SQL查询,这通常是卓有成效的,但它似乎是使用MySQL。
我也有尝试过其他变体,如
where date >= ifnull(@datefrom, date)
也
where ((date >= @datefrom and @datefrom is not null) or (@datefrom is null))
但林没有得到结果,我期待..
有人可以阐明这个任何光?
过程定义为这样..
CREATE DEFINER=`root`@`%` PROCEDURE `prc_xxxxxx`(datefrom datetime)
BEGIN
select * from table
where date >= @datefrom or @datefrom is null
END
,然后我将调用这样的..
call prc_xxxxxx ('2012-07-04 00:00:00')
或
call prc_xxxxx (null)
您是否正在运行此查询?与查询中的@ – Dojo
是 - 与@ – Grant
尝试使用'NULL'安全的相等运算符['<=>'](http://dev.mysql.com/doc/en/comparison-operators.html#operator_equal-to)。 – eggyal