-->
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: How to Give Format to Value
PostPosted: Tue Jun 19, 2007 12:38 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
I am trying a hql like this

Select avg((totalScore/maxScore)*100) from XBean
When I am getting its result. Result is having 7 digits as precision. I want to set its width and precision. How can I do the same ?

Thanks,
Gopal


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 2:16 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

try this

Select CONVERT(decimal(10,5), avg((totalScore/maxScore)*100)) from XBean



Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 12:04 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
Thnx Amila,

I already tried the same thing. java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode and java.lang.NullPointerException Exceptions are coming. I am applying the same thing suggested by you. But This is not working.


Thnx,
Gopal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 12:35 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

ok Gopal , Actually I didn't test it.

You can do it like this.

in your mapping file you can define a property for a formula

Code:
<property
            name="formulaField"
            type="java.lang.String"
            update="true"
            insert="true"
            formula="avg((totalScore/maxScore)*100"
            precision="7"
            scale="2"

        />


Select formulaField from XBean


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 8:33 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
[quote="amila733"]Hi

ok Gopal , Actually I didn't test it.

You can do it like this.

in your mapping file you can define a property for a formula

Code:
<property
            name="formulaField"
            type="java.lang.String"
            update="true"
            insert="true"
            formula="avg((totalScore/maxScore)*100"
            precision="7"
            scale="2"

        />


Select formulaField from XBean


Hi Amila,


Sorry for late reply. I tried the same suggested by you. i am not getting precision set. I also tried with length attribute. but This is not working. Is There not a way to set this in the query itself ?

Thanks,
Gopal


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.