named parameters - HQL Query with multiple Criteria -
I am trying to write an HQL query which selects rows from the table based on several criteria. First name, last name
It is a catch that the query must be flexible to ignore any empty or zero values
such a
from the table Select t (: Firstname = '' or t.firstName =: firstName) AND (: lastName = '' OR t.lastName =: lastName)
I would have thought that this would work ? But this is not - does it ever return any rows? Any thoughts that might be wrong here? I am very new to why this question is.
If I understand correctly, you can search the user by first, last name or both You should check that if the passed parameter is empty, do not make it a condition if they provide all the blank parameters then it will return the whole table Try:
Select the table where (: firstname is IS NULL or t.firstName =: firstName) and (: lastName IS NULL or t.lastName =: lastName)
Comments
Post a Comment