Question: For example take this jpql query -

```
@Query("SELECT account.name, account.type From AccountEntity account WHERE account.id=:accountId")
getAccountNameById(@Param(accountId) int accountId); //i know Spring Data Derived Query can handles this automatically - but lets not use this for this discussion.

```

in the above jpql query, if no accountId is passed, i want to select records for all accountId's. Is it possible. I know i can use another query - getAllAccounts() and call it from service layer based on accountId is present or not. But I have to handle it from repo in this case.

So is it possibel that JPQL returns all records when parm value is missing or null.

Answer: 
A little bit late but...

In this example the 1st WHEN is going to evaluate :accountId
if it's null then the query is going to return all elements,
in the 2nd WHEN if :accountId is not null then is going to return all elements
where account.id = :accountId

```
SELECT account.name, account.type FROM AccountEntity account 
WHERE CASE WHEN :accountId IS NULL THEN TRUE
WHEN :accountId IS NOT NULL AND account.id = :accountId THEN TRUE ELSE FALSE END

```
test if parameter is null

```
SELECT account.name, account.type From AccountEntity account WHERE (:accountId is null or account.id=:accountId)

```