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.  [ 2 posts ] 
Author Message
 Post subject: HQL: Usage of "case-when-then-else-end" with a where clause?
PostPosted: Tue Mar 09, 2010 5:56 am 
Beginner
Beginner

Joined: Thu Oct 16, 2008 11:19 am
Posts: 23
Location: Norway
I'm trying to use this with a where clause, but I can't just seem to get the hang of it. I also can't find many good examples online. I understand that there are two different versions, but I'm not sure which one suits my problem the best.

What I'm trying to achieve to make a where clause dependent on the value of a column. Something like this in pseudo code:

where car.brand = 'SAAB' when car.country = 'Sweden'

I hope that makes sense. Are anyone experienced in using these and can help me out with some examples?


Top
 Profile  
 
 Post subject: Re: HQL: Usage of "case-when-then-else-end" with a where clause?
PostPosted: Tue Mar 09, 2010 8:29 am 
Beginner
Beginner

Joined: Thu Oct 16, 2008 11:19 am
Posts: 23
Location: Norway
I think I have found the answer myself, after some further digging online. Something like this:

where car.brand = case when car.country = 'Sweden' then 'SAAB' (else whatever) end


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

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.