Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / March 2005

Tip: Looking for answers? Try searching our database.

Sorting a field with text and numbers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MacNut - 10 Mar 2005 15:59 GMT
I have a field with information in this type of format:  NB-TS-WP-46048 and i
was wondering HOW I could sort based on those LAST 5 numerical digits.  Right
now, it's sorting in ascending order based on the first 2 characters.  

Is this possible?

Thanks
JaRa - 10 Mar 2005 16:17 GMT
Yep you can
You can add an extra column  to your query

e.g. SELECT Column FROM Table ORDER BY Right(Column,5)

- Raoul

> I have a field with information in this type of format:  NB-TS-WP-46048 and i
> was wondering HOW I could sort based on those LAST 5 numerical digits.  Right
[quoted text clipped - 3 lines]
>
> Thanks
MacNut - 10 Mar 2005 16:35 GMT
Perfect.  Thanks so much!!
MN

> Yep you can
> You can add an extra column  to your query
[quoted text clipped - 10 lines]
> >
> > Thanks
John Nurick - 10 Mar 2005 16:23 GMT
Add a calculated field to your query, like this:

   SortOrder: Right([XXX], 5)

where XXX is the field name. Then sort on the calculated field.

If you have a large number of records this will be quite slow. Consider
separating the last five digits into a field of their own and indexing it.
If the different parts of your field have their own meanings there's a
strong argument for splitting them into separate fields anyway.

>I have a field with information in this type of format:  NB-TS-WP-46048 and
>i
[quoted text clipped - 5 lines]
>
> Thanks
Tim Ferguson - 10 Mar 2005 18:52 GMT
>  i
> was wondering HOW I could sort based on those LAST 5 numerical digits

 SELECT Whatever
 FROM Wherever
 ORDER BY RIGHT(MyField, 5) ASC

You might also think about normalising the table design...

B Wishes

Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.