I have a mySql query in which i want to select the records on certain values which i am providing in where clause, these values i am getting dynamically from spring mvc form, how to make sure that if any one of the value is null then ignore that condition check in where clause and check for other not null values.
Here is my query
SELECT qrule.id ruleId
,com.vc_company_name company
,cdef.vc_className className
,qrule.vc_ruleName rule
,qrule.dt_modifiedOn modifiedOn
,qrule.in_modifiedBy modifiedBy
FROM ne_company com qualification_rule qrule, classdefintion cdef
WHERE com.company_id = 42
AND com.in_status = 13
AND cdef.id = 7
AND qrule.vc_ruleName LIKE 'h%'
all values in where clause is dynamically generated, what i want is that when company_id is null then com.company_id = 42 this check should be ignored and query should perform like
SELECT qrule.id ruleId
,com.vc_company_name company
,cdef.vc_className className
,qrule.vc_ruleName rule
,qrule.dt_modifiedOn modifiedOn
,qrule.in_modifiedBy modifiedBy
FROM ne_company com qualification_rule qrule, classdefintion cdef
WHERE com.in_status = 13
AND cdef.id = 7
AND qrule.vc_ruleName LIKE 'h%'
and the same goes for every column.
NOTE: One value is mandatory so we have provided that check,