473,382 Members | 1,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

sort by numeric part of a field

Hello,
I must sort a table width only one column. Inside the field I have, for
example, hard disk capacity (something like '100Gb' or '80Gb' or
'80Gbyte' or 'Gb80').

So, if I use ORDER BY ... DESC, 80Gb will be before 100Gb and other
errors.

How can i sort the table only on the numeric part of the field?

I'm trying using CAST() but with no results.

Thank you very much
Andrea

Jul 26 '06 #1
3 4929
I'd say to try to substring for G (both lower and upper case and any other
letters you may need for example M) and then drop everything after that
position. This will leave you only the digits.

-s
On 7/26/06 06:35, in article
11*********************@m73g2000cwd.googlegroups.c om,
"an****************@libero.it" <an****************@libero.itwrote:
Hello,
I must sort a table width only one column. Inside the field I have, for
example, hard disk capacity (something like '100Gb' or '80Gb' or
'80Gbyte' or 'Gb80').

So, if I use ORDER BY ... DESC, 80Gb will be before 100Gb and other
errors.

How can i sort the table only on the numeric part of the field?

I'm trying using CAST() but with no results.

Thank you very much
Andrea
Jul 26 '06 #2
an****************@libero.it wrote:
How can i sort the table only on the numeric part of the field?
....ORDER BY 0 + harddiskcapacity

This coerces the column to be evaluated as an integer. It uses the
digits in the leading portion of the value, to form an integer.
In other words, the expression 0 + '80Gb' returns the integer value 80.

Regards,
Bill K.
Jul 30 '06 #3
yes!
very good, you solved my problem!
Thank you very much
Andrea

Bill Karwin ha scritto:
an****************@libero.it wrote:
How can i sort the table only on the numeric part of the field?

...ORDER BY 0 + harddiskcapacity

This coerces the column to be evaluated as an integer. It uses the
digits in the leading portion of the value, to form an integer.
In other words, the expression 0 + '80Gb' returns the integer value 80.

Regards,
Bill K.
Aug 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rolf Kemper | last post by:
Hi All, I'm quite sure that somebody of you have already a solution for this: ABC1 ABC12 ABC2 ABC21 ABC3
10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
11
by: James P. | last post by:
Hello, I have a report with the Priority field is used as sort order and grouping. The problem is the data in this Priority field if sorted in ascending order is: High, Low, and Medium. How...
2
by: steve.turner | last post by:
Hi all, I'm hoping someone can stop me tearing (what's left of) my hair out over this problem... I have a linked Excel file from which I append the data to an empty local Access table. I...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
20
by: Bill Waddington | last post by:
This must be a FAQ - or several FAQs - but I can't quite seem to pin it down. I need to read a string from stdin which I will then process as digits with sscanf. I need to limit the # of chars...
0
by: kronus | last post by:
Hi everyone, Please tell me what I am doing wrong: I have an xml data coming to my Air application that looks something like this: <project name="Sales Demos" path="/Company Home/Client...
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following function to get the data from mysql database. i have entered appnum field as text filed in the database which has leading zeroes to this field like if...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.