-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: case statement in select
PostPosted: Thu Jan 21, 2010 5:18 am 
Newbie

Joined: Thu Jan 21, 2010 5:08 am
Posts: 3
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,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.