You can use "and" in the sleeping "case, when ... then ... more ... end"?

I have the following query:

select myentity from TEST as test
left join test.org.parent as parentOrg
left join test.clientRequest as clientReq
where test.customId = 1 and (test.dstatus = 1 or test.cm = true)
order by (case when test.request != '' then test.request else clientReq.name end) asc;

It is working correctly. But I need not only clientReq.name, but also clientReq.surname. Is it possible to combine these two columns in this case when...then...else...end?

Sort of:

order by (case when test.request != '' then test.request else (clientReq.name and clientReq.surname) end) asc;

This exception excludes:

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node
+3
source share
1 answer

Since you are sorting, I assume you want to combine the first and last name:

order by (case when test.request != '' then test.request else concat(clientReq.name,clientReq.surname) end) asc;

See the HQL Query Expressions in the docs for more details .

+2
source

All Articles