[英]How to add where condition clause dynamically in mySql Procedure
where
b.deviceId=device_id_U
and(
CONCAT('%',COALESCE(device_id_U,''),'%') and
b.searchTerm like
CONCAT('%',COALESCE(search_term,''),'%') and
b.deviceName like
CONCAT('%',COALESCE(device_name,''),'%') and
b.deviceNumber like
CONCAT('%',COALESCE(device_Number,''),'%') and
b.os like
CONCAT('%',COALESCE(device_os,''),'%') and
b.deviceWorkingStatus like
CONCAT('%',COALESCE(device_workingstatus_U,''),'%') and
b.status like
CONCAT('%',COALESCE(device_status_U,''),'%') )
;
end if;
END
This is my Procedure i want when i pass device_id null then it should ignore where condition with device id and if give device_id value then it should search device id wise please tell me how add dynamically where condition so that i can solve this issue i am facing problem to add where clause dynamically 这是我想要的过程,当我通过传递device_id null时,它应该忽略带有设备ID的条件,如果给定device_id值,那么它应该明智地搜索设备ID,请告诉我如何动态添加条件,以便我可以解决此问题动态添加where子句的问题
您可以尝试使用@FDavidov的想法进行反转吗
where b.deviceId= IFNULL(device_id_U , b.deviceId)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.