-->
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: Convert from String to Integer in SQL
PostPosted: Fri Jun 05, 2009 2:28 pm 
Newbie

Joined: Sat Dec 30, 2006 3:07 pm
Posts: 16
I would like to order by a String, which in some cases I know contains an integer.

Like this

select * from vo_meta_data where md_key="relevance" order by CONVERT(md_value, SIGNED) desc;

here md_value is stored as a string, but in this perticular case I know it is an integer.

The problem is that if I have values "100", and "8" they are ordered incorrectly.

I could 0 pad, but I prefer not to do that if there is an HQL alternative.


Top
 Profile  
 
 Post subject: Re: Convert from String to Integer in SQL
PostPosted: Sun Jun 07, 2009 5:08 am 
Beginner
Beginner

Joined: Mon Jun 01, 2009 5:39 am
Posts: 34
You can use the cast function:

Code:
select * from vo_meta_data where md_key = 'relevance' order by cast(md_value, int);


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.