1

I have the following query:

SELECT p FROM dbEntity p where p.name like %:nameFilter% 

nameFilter is default an empty String (""), it can also be set to a string the user can enter.

Now the default case gets all rows where the name column is either filled with text or is set to an empty string.
However, there are also rows where name is set to NULL.

How can I change my query to also return the rows with NULL, but only if nameFilter is an empty String?

0

1 Answer 1

2

You can use coalese and convert nulls as empty strings so that it be retrived,

 SELECT p FROM dbEntity p where coalesce(p.name,"") like %:nameFilter% 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.