I have an alphanumeric field that I'd like to order, but Access does not recognize the numbers in the proper order. The field contains a work breakdown structure numbering scheme similar to what you'd see in a detailed job description. So, for example...
MG 1.1
MG 1.1.3
MG 1.10
MG 1.2
The problem is that when I try to sort, access will order in the following way:
MG 1.1
MG 1.10
MG 1.1.3
MG 1.2
How can I change this? Any help is appreciated!
8 5952
Access does not recognize the numbers in the proper order.
is a false statement. Access does recognize numbers in the proper order, as well as letters and punctuation marks. The problem is that you're not asking Access to sort numbers, but rather alpha-numeric characters, as you indicated in the post title, which include letters, numbers and periods/decimal points! Access is doing exactly what you've asked it to do! When sorting an alpha-numeric field Access, like every other computer based system, sorts using the ASCII Table, where the period/decimal point comes before numeric characters.
Perhaps someone here knows of a work around.
To use an alphanumeric sort on your data you would need to change it into:
MG 1.01
MG 1.01.03
MG 1.02
MG 1.10
etc.
So two positions with leading zero when < 10.
When the max number for the second level is e.g. 101, then you would need:
MG 1.001
MG 1.001.03
MG 1.002
MG 1.010
MG 1.101
When you want this easier you would need to use different fields like: -
Code Level1 Level2 Level3
-
MG 1 1 0
-
MG 1 1 3
-
MG 1 10 1
-
etc.
Now you can use numbers for the Level# fields and get them sorted the way you expect.
Finally you could split the data (using a function or IIF() and MID() statements) and sort on that onstead of the complete field.
Nic;o)
To use an alphanumeric sort on your data you would need to change it into:
MG 1.01
MG 1.01.03
...
There are probably other ways it could be done, but they may become rather messy. For example, to avoid changing your data, in a query you could... - Create a calculated field which converts the format of the number to avoid changing your data. In other words, it could combine the first two characters and the numeric value of the rest of the field, formatted with leading zeroes.
- Create two calculated field. One would hold the "MG" part of the field. The other would hold the number part, as a number.
The fact that your "number" has more than one decimal point may complicate things. For one thing, the Val( ) function probably won't like it.
I rather like the idea of including each level in a separate field though, as nico suggested - holding information in a more structured way like that could provide numerous benefits further down the track, as well as simplifying this sort. To pluck one trivial example out of thin air, if you later change your mind about the format in which the data should be displayed, it would probably be easier. Or if you suddenly came up with a need to search by various levels within the number.
Indeed The fact that your "number" has more than one decimal point means that it isn't a number at all, and certainly will complicate things!
Good Luck!
NeoPa 32,556
Expert Mod 16PB
The options already posted are good answers to what is quite a difficult concept.
Another answer which would suit some people better (depending on what they are most comfortable with) is to define a globally available function which takes in the string you currently use and re-formats it in such a way that it could be sorted in the way you would like - similar to Nico's layout.
Once that were created you would have the original string available for display and you could order by the returned result of the function.
The options already posted are good answers to what is quite a difficult concept.
Another answer which would suit some people better (depending on what they are most comfortable with) is to define a globally available function which takes in the string you currently use and re-formats it in such a way that it could be sorted in the way you would like - similar to Nico's layout.
Once that were created you would have the original string available for display and you could order by the returned result of the function.
One thing to keep in mind though, using a function-derived value for sorting in this way could have big performance implications. If we're talking about relatively small amounts of data for the processing power available, then no matter. Otherwise, it might be better to use the function at time of record creation/update, and store the derived value in the record, then use this column in sorting.
NeoPa 32,556
Expert Mod 16PB
This is true.
Storing the data differently would have to be an 'also' rather than an 'instead of' though.
Like the change back of the avatar Killer.
This is true.
Storing the data differently would have to be an 'also' rather than an 'instead of' though.
Oh, definintely. The idea was to add a redundant copy of the field, for use as a sorting index.
Like the change back of the avatar Killer.
Thanks. I think the orange tunnel one is my favourite (so far).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ken Fine |
last post by:
(originally posted to one of macromedia's groups; no help, so hopefully
someone here can help me out. I'm using VBScript ASP.)
When designing administrative interfaces to websites, we often need...
|
by: nospam |
last post by:
NEWS.COM
Amazon wins patent for ordering forms
# 6,615,226 http://tinyurl.com/m7v8
http://news.com.com/2100-1017-5070569.html
In its latest patent, the online retailing giant outlined a...
|
by: masood.iqbal |
last post by:
What is the standard C/C++ lexicograhic ordering of punctuation
characters with respect to each other and the alphanumeric characters?
--Masood
|
by: Matt |
last post by:
I want the javascript to test an alphanumeric (a string contains
alphabet or numbers only) string. Should I write a regular expression?
What's the best way to do? please help. thanks
|
by: ironcito |
last post by:
Hello!
I'm looking for a way to have a field in my database that will
automatically be filled with a random 4-character alphanumeric string
every time I enter a new record. Like an autonumber...
|
by: Chris |
last post by:
Any good routines or suggestions to assist me in re-ordering my records in my
datagrid?
i.e. I have a field in each record that is used for ordering (i.e. 1,2,3,4).
I would like to implement a...
|
by: John |
last post by:
Hi
How can I select records that have non-alphanumeric characters in a field
using a select query?
Thanks
Regards
|
by: bill |
last post by:
I have a database of kennels. One page lists the kennels
alphabetically by kennel name.
I have a field for kennel name and an index with kennel name as
the only field.
Some of the kennels have...
|
by: Paul73 |
last post by:
Hi everyone,
I'm hoping someone can help me. I've created a windows app that inserts data into a sql database.
The data comes from textboxes. This is a simple app that will only be used by...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |