-->
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.  [ 4 posts ] 
Author Message
 Post subject: CASE WHEN in select clause and *= in Where clause
PostPosted: Thu Sep 08, 2005 9:58 am 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Hi,

I need to sort a result set on a computed column. The computed column use to be coded like this:

case when myTable.orgId = 1 then myTable.orgName when myTable.orgId <> 1 and UPPER(Form.formLanguage) = 'F' then Organization.nameFrench when myTable.orgId <> 1 and UPPER(Form.formLanguage) = 'E' then Organization.nameEnglish end as organizationName

I upgraded from Hibernate 2.1.4 to 3.0.5 because I read in the change log that the CASE WHEN was implemented in version 3.0.4. Now, I tried to make that query work for a while but can't figure out how to do it. Hibernate always return the error "undefine alias case...".

Also, since I upgraded, all my HQL that have a "*=" or "=*" in the Where clause don't work... I have to use the org.hibernate.hql.classic.ClassicQueryTranslatorFactory avoid that problem.

I'm thinking, if I use the old SQL parser maybe the Case When will not work.

Thanks in advance for your help


Hibernate version:3.0.5

Name and version of the database you are using: Sybase ASE 12


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:12 am 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
Ok, I kept working at it and was able to get the CASE WHEN working. The problem was related to spaces between operators an operands like "this <> 1" had to be "this<>1".

Now, for the CASE WHEN to work I have to use the org.hibernate.hql.ast.ASTQueryTranslatorFactory. But that SQL parser does not understand "*=".


What can I use to replace this, in my WHERE clause? Do I have to use "left join" in the from clause?

Is there a way to make the "*=" to work when using the ASTQueryTranslatorFactory.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 11:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
massep wrote:
Ok, I kept working at it and was able to get the CASE WHEN working. The problem was related to spaces between operators an operands like "this <> 1" had to be "this<>1".


huh?? I find this very, very hard to believe.

massep wrote:
Now, for the CASE WHEN to work I have to use the org.hibernate.hql.ast.ASTQueryTranslatorFactory. But that SQL parser does not understand "*=".


You should use ANSI-style outerjoins.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 2:08 pm 
Regular
Regular

Joined: Thu Aug 19, 2004 9:28 am
Posts: 63
You should use ANSI-style outerjoins.[/quote]


I'm trying to translate my WHERE clause in to the ANSI equivalent FROM clause... Maybe you could help?

Here's what I'm trying to convert:

SELECT Address.lastName, Address.givenName, Cities.name, Provinces.name From Address Address, Cities Cities, Provinces Provinces
Where Address.cityCode *= Cities.code and Address.provinceCode *= Provinces.code

So, it's basically 1 main table with 2 code columns and I have to get the name for those codes if the codes exist in the code tables (Cities & Province).

Ex.result set:
Smith, Joe, Ottawa, Ontario.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.