Trying to use a case statement as part of the select in hql.
Code:
Select uniqueId,
case
when ? = 1 then varchar_column
else null
end as sort_varchar,
case
when ? = 2 then int_column
else null
end as sort_int,
case
when ? = 3 then date_column
else null
end as sort_datetime
from Programme
where parentEntity.id = ?
order by sort_varchar, sort_int, sort_datetime
given params of three ints then a long.
says
Code:
No data type for node: org.hibernate.hql.ast.tree.CaseNode
+-[CASE] CaseNode: 'case'
| +-[WHEN] SqlNode: 'when'
| | +-[EQ] BinaryLogicOperatorNode: '='
| | | +-[PARAM] ParameterNode: '?' {ordinal=0, expectedType=org.hibernate.type.IntegerType@549ad840}
| | | \-[NUM_INT] LiteralNode: '1'
| | \-[IDENT] IdentNode: 'varchar_column'
| \-[ELSE] SqlNode: 'else'
| \-[NULL] SqlNode: 'null'
Can someone explain what this message means and how to fix it?
I've also tried writing it along the lines of
Code:
case ?
when 1 then varchar_column
else null
end as sort_varchar
but that doesn't work either.
Are Case statements in selects supported? With parameters? If so, what am I doing wrong?
Thanks,