473,406 Members | 2,352 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,406 software developers and data experts.

Sorting Numbers in Access97

I need some help with sorting some part numbers that are
alphanumeric. I have a table with a part number field which are in
the following format--sw1000, sw1200, sw2000, sw2600, sw3000, sw21000,
sw30200 etc..
When I sort that field in the table I want them to be sorted in order
chronologically starting with the lowest value to the highest value.
When I use the sort feature in access it sorts them, but not from
least to greatest--it sorts all the "ones", then all the "two's", then
all the "threes's" etc., I want them sorted thousands, ten
thousands, twenty thousands, etc.
The first two characters of the part number are always going to be
alpha. Any insights would be greatly appreciated. Thanks.

Feb 19 '07 #1
5 2554
On Feb 19, 2:24 pm, "JJM0926" <jjm0...@gmail.comwrote:
I need some help with sorting some part numbers that are
alphanumeric. I have a table with a part number field which are in
the following format--sw1000, sw1200, sw2000, sw2600, sw3000, sw21000,
sw30200 etc..
When I sort that field in the table I want them to be sorted in order
chronologically starting with the lowest value to the highest value.
When I use the sort feature in access it sorts them, but not from
least to greatest--it sorts all the "ones", then all the "two's", then
all the "threes's" etc., I want them sorted thousands, ten
thousands, twenty thousands, etc.
The first two characters of the part number are always going to be
alpha. Any insights would be greatly appreciated. Thanks.
Try something like this:

SELECT [Table1].[PartNo]
FROM Table1
ORDER BY CLng(Mid([PartNo],3));

Feb 19 '07 #2
On Feb 19, 3:24 pm, "JJM0926" <jjm0...@gmail.comwrote:
I need some help with sorting some part numbers that are
alphanumeric. I have a table with a part number field which are in
the following format--sw1000, sw1200, sw2000, sw2600, sw3000, sw21000,
sw30200 etc..
When I sort that field in the table I want them to be sorted in order
chronologically starting with the lowest value to the highest value.
When I use the sort feature in access it sorts them, but not from
least to greatest--it sorts all the "ones", then all the "two's", then
all the "threes's" etc., I want them sorted thousands, ten
thousands, twenty thousands, etc.
The first two characters of the part number are always going to be
alpha. Any insights would be greatly appreciated. Thanks.

I've not had to do this before, but perhaps you could sort on a
calculated field.
Example...SELECT ....... ORDER BY CLng(Mid([PartNumber],3));

Feb 19 '07 #3
JJM0926 wrote:
The first two characters of the part number are always going to be
alpha. Any insights would be greatly appreciated. Thanks.
Sort on this calculated field:

val(mid(MyPartNumberField,3))

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Feb 19 '07 #4
On Feb 19, 1:33 pm, Tim Marshall
<TIM...@PurplePandaChasers.Moertheriumwrote:
JJM0926 wrote:
The first two characters of the part number are always going to be
alpha. Any insights would be greatly appreciated. Thanks.

Sort on this calculated field:

val(mid(MyPartNumberField,3))

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
What Gord had me tried work perfectly. I then changed that to a make-
table query and I got my new table sorted the way I wanted. Thanks
all.

Feb 19 '07 #5
"JJM0926" <jj*****@gmail.comwrote
What Gord had me tried work perfectly. I then
changed that to a make-table query and I got my
new table sorted the way I wanted.
You may be disappointed to know that data in relational tables is, by
definition, unordered. Access has to display it in some order, but you can't
count on that order in every situation. If you want the data ordered in a
particular sequence, you need to retrieve it with a Query specifying the
Fields on which it is to be sorted (which will be represented in the
corresponding SQL statements as an ORDER BY clause).

However, to obtain the order that you wish, you must separate the "numeric"
part of the text Field, and convert it to a number, as you were instructed
and as you did.

Larry Linson
Microsoft Access MVP
Feb 20 '07 #6

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

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
22
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
7
by: Foodbank | last post by:
Hi everyone. I'm having trouble with this radix sorting program. I've gotten some of it coded except for the actual sorting :( The book I'm teaching myself with (Data Structures Using C and...
9
by: Dylan Parry | last post by:
Hi folks, I have a database that contains records with IDs like "H1, H2, H3, ..., Hn" and these refer to local government policy numbers. For example, H1 might be "Housing Policy 1" and so on....
5
by: ^cypis^ vel. SQ9JTI | last post by:
Hi there, i have a problem. I prepared bucket sorting with reading values from file (data.txt) and saving to other file (aus.txt). Everything is good if we talk about reading and sorting, but...
3
by: Mark | last post by:
Hi All, I have wrote a sub to record events from within the database. A lot of these events are errors. The sub has the module name and function/sub name passed to it to record to the table. My...
6
by: carlos123 | last post by:
I have a programming assignement that i have been working on for quite some time now. I need your guys' help. My assignement is to great a table with data in it. and it will have a combobox and 2...
7
beacon
by: beacon | last post by:
I'm writing a program as an assignment that takes 5 sorting algorithms and and tests for the amount of time and the number of comparisons it takes to um, sort an array. I have run into some...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.