我想从同一个SP中选择所有客户或一个客户。现在我们正在mantaining两个SP来获得这些信息:我的SQL:如果在where语句中添加条件?
即要获得所有客户:
select id, name from customers
,并获得一个客户:
select id, name from customers
where id=id_from_input
使它们成为通用,我想的将id_from_input
定为空以获得所有客户。我尝试了几种方法在sql中创建一个条件where语句,该语句可用于此计划,但没有任何工作。例如:
select id, name from customers
where if(id_from_input <> null) id=id_from_input; end if
给我语法错误。
如何在id_from_input
为空时返回所有行的where
子句,否则为匹配行?
'CASE WHEN'是查询了'IF'语法。 – Hexxed