-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem in running SQL query carrying anonymous column
PostPosted: Tue Aug 21, 2007 7:57 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:10g

Hello All,

I have encountered an exception while running this query in hibernate.
String str6 = "SELECT TO_CHAR(ADD_MONTHS( TO_DATE(?,'DD/MM/YYYY'), (ROWNUM-1)),'Mon-YYYY') as MONYR, ADD_MONTHS(TO_DATE(?,'DD/MM/YYYY'),(ROWNUM-1)) as DD_DATE FROM CL_Enroll as clEnroll WHERE ROWNUM <= MONTHS_BETWEEN(TO_DATE(?,'DD/MM/YYYY'),TO_DATE(?,'DD/MM/YYYY'))+1 ORDER BY DD_DATE ASC";

The error is "DD_DATE": invalid identifier

when I run this query after removing the bold portion , the query runs successfully.But I need to add the order by clause.
This runs successfully:-
String str6 = "SELECT TO_CHAR(ADD_MONTHS( TO_DATE(?,'DD/MM/YYYY'), (ROWNUM-1)),'Mon-YYYY') as MONYR, ADD_MONTHS(TO_DATE(?,'DD/MM/YYYY'),(ROWNUM-1)) as DD_DATE FROM CL_Enroll as clEnroll WHERE ROWNUM <= MONTHS_BETWEEN(TO_DATE(?,'DD/MM/YYYY'),TO_DATE(?,'DD/MM/YYYY'))+1

So how can I order the result set on the basis of anonymous column which in my case is DD_DATE .

Thanx in Advance.

Regards,
Abhishek


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 8:01 am 
Newbie

Joined: Tue Aug 21, 2007 7:11 am
Posts: 2
try :
ORDER BY clEnroll.DD_DATE ASC


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 8:21 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Hello,
Thanx for the fast reply, but I had tried this earliar, but that don't work.

I am getting an error:-

could not resolve property: DD_DATE of: CL_Enroll [SELECT TO_CHAR(ADD_MONTHS( TO_DATE(?,'DD/MM/YYYY'), (ROWNUM-1)),'Mon-YYYY') as MONYR, ADD_MONTHS(TO_DATE(?,'DD/MM/YYYY'),(ROWNUM-1)) as DD_DATE FROM CL_Enroll as clEnroll WHERE ROWNUM <= MONTHS_BETWEEN(TO_DATE(?,'DD/MM/YYYY'),TO_DATE(?,'DD/MM/YYYY'))+1 ORDER BY clEnroll.DD_DATE ASC]

As DD_DATE is not a property of CL_Enroll class.

So what I would do...

Regards,
Abhishek


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 11:50 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
This should work:

SELECT TO_CHAR(ADD_MONTHS( TO_DATE(?,'DD/MM/YYYY'), (ROWNUM-1)),'Mon-YYYY') as MONYR, ADD_MONTHS(TO_DATE(?,'DD/MM/YYYY'),(ROWNUM-1)) as DD_DATE FROM CL_Enroll as clEnroll WHERE ROWNUM <= MONTHS_BETWEEN(TO_DATE(?,'DD/MM/YYYY'),TO_DATE(?,'DD/MM/YYYY'))+1 ORDER BY ADD_MONTHS(TO_DATE(?,'DD/MM/YYYY'),(ROWNUM-1)) ASC

(repeat the calculations in the order by)

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 12:39 am 
Newbie

Joined: Mon Aug 13, 2007 6:38 am
Posts: 16
Hello nathan,
Yes, its working now...Thanx once again.

Regards,
Abhishek


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