473,378 Members | 1,471 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,378 software developers and data experts.

Sorting with letters

I have a database where I label entries by the alphabet (A-Z). However, when I have more entries than the alphabet has letters I then double the letters (AA-ZZ) and so on.

I want to create a sorting code that will list all single letters then double letters, triple and so on.

I am somewhat of a novice so if anyone has some ideas I sure would appreciate it along with a bit of detail.

Thanks much!
Adam
Apr 9 '09 #1
18 3451
FishVal
2,653 Expert 2GB
Hello, Adam.

Try something like the following:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [YourTable] ORDER BY Len([Label]), [Label];
  2.  
Apr 9 '09 #2
Sorry, I am working in MS Access and am not that familiar with VB Coding. Could you provide a bit more detail on how to complete your suggestion?

Thanks!
Apr 9 '09 #3
FishVal
2,653 Expert 2GB
Queries in Access using SQL View
Basic SQL Syntax for Access Queries

http://en.wikipedia.org/wiki/Select_(SQL)

What makes records to be ordered is what is written in ORDER BY clause of SQL expression:
Expand|Select|Wrap|Line Numbers
  1. ... ORDER BY Len([Label]), [Label];
  2.  
this tells database engine to sort records first by length of [Label] field, then by value of [Label] field.
I guess in query design view grid it looks like column "ExprN: Len([Label])" with ascending sorting order and "[Label]" column with ascending sorting order rightward to it.
Apr 9 '09 #4
FishVal-

I appreciate the help but this does me no good. I have no idea what you are trying to explain, even though I have read through it a few times. I attempted to modify my query with sort example but all I got was a bunch of errors.

Anyone else wanna take a stab at helping out?

Thanks
Adam
Apr 10 '09 #5
FishVal
2,653 Expert 2GB
Ok, Adam.

Open your query, change View to SQL, post contents of query window.
Apr 10 '09 #6
NeoPa
32,556 Expert Mod 16PB
A QueryDef (saved query in Access) has two different ways that its design can be shown in Access :
  1. Design View.
  2. SQL View.
When either is displayed, the other can be selected by using the View menu and selecting the relevant option. What this means is that when changes are made in either view, the changes are visible in both.

Because of this, we can get a pretty good idea of what your query is doing simply by looking at the SQL (that you can see and post here for us simply by using the SQL view). It also means that we can give you changes to the SQL that you will be able to put into the SQL view of the QueryDef, and see the intended changes in Design view.
Apr 16 '09 #7
Thanks for the explanation...here is the SQL info that I was able to recover:
Expand|Select|Wrap|Line Numbers
  1. SELECT   Entrys.SPDCaseNumber,
  2.          Entrys.Location,
  3.          Entrys.LedgerNumber,
  4.          Entrys.OfficerID,
  5.          Entrys.ReceivedDate,
  6.          Entrys.[EvidenceDisposed?],
  7.          Entrys.EvidenceTypeID,
  8.          [Entry Details].LedgerID,
  9.          [Entry Details].EvidenceName,
  10.          [Entry Details].Quantity,
  11.          [Entry Details].Notes,
  12.          [Entry Details].ItemNumber,
  13.          Entrys.EvidenceTypeID,
  14.          Entrys.[Warrant?],
  15.          Entrys.CaseResolvedDate,
  16.          Entrys.TobeDisposed
  17.  
  18. FROM     Entrys INNER JOIN [Entry Details]
  19.   ON     Entrys.LedgerID = [Entry Details].LedgerID
  20.  
  21. ORDER BY Entrys.LedgerNumber,
  22.          [Entry Details].ItemNumber
Apr 23 '09 #8
NeoPa
32,556 Expert Mod 16PB
I'll try to look at this in more detail later, but for now I've just rearranged the code so that it's a little easier to read and digest.
Apr 23 '09 #9
NeoPa
32,556 Expert Mod 16PB
@awojciehowski
Adam, can you say which field you're referring to here? The one where you store the alphabetic characters.
Apr 23 '09 #10
It would be the Item Number field that I would want to be organized as A, B, C then AA, BB, CC then AAA, BBB, CCC and so on.
Apr 23 '09 #11
NeoPa
32,556 Expert Mod 16PB
In that case add some spaces at the front then chop off the rightmost n characters. I worked to a potential maximum of 5 chars, but you know your data better than I.

The other change I made (setting and using the ALIASes) had no real effect, it simply makes it easier to read and work with when in SQL view.
Expand|Select|Wrap|Line Numbers
  1. SELECT   tE.SPDCaseNumber,
  2.          tE.Location,
  3.          tE.LedgerNumber,
  4.          tE.OfficerID,
  5.          tE.ReceivedDate,
  6.          tE.[EvidenceDisposed?],
  7.          tE.EvidenceTypeID,
  8.          tED.LedgerID,
  9.          tED.EvidenceName,
  10.          tED.Quantity,
  11.          tED.Notes,
  12.          tED.ItemNumber,
  13.          tE.EvidenceTypeID,
  14.          tE.[Warrant?],
  15.          tE.CaseResolvedDate,
  16.          tE.TobeDisposed
  17.  
  18. FROM     Entrys AS tE INNER JOIN [Entry Details] AS tED
  19.   ON     tE.LedgerID=tED.LedgerID
  20.  
  21. ORDER BY tE.LedgerNumber,
  22.          Right('    ' & tED.ItemNumber,5)
Apr 23 '09 #12
NeoPa
32,556 Expert Mod 16PB
You could also use Fish's technique (which I missed). Just replace lines #21 & #22 with :
Expand|Select|Wrap|Line Numbers
  1. ORDER BY tE.LedgerNumber,
  2.          Len(tED.ItemNumber),
  3.          tED.ItemNumber
This is actually a better, more flexible technique anyway. I'd go with this version for preference.
Apr 23 '09 #13
NeoPa-

I copied and pasted what you suggested into my query...now when I view the record it still is not sorted correctly and when I click on a button to print the current record is comes up with an missing parameter value of "Entry Details.Evidence Name".

I am attaching a screen shot for you to understand what I am looking at.

Apr 23 '09 #14
NeoPa
32,556 Expert Mod 16PB
That makes the problem very clear Adam. I'm afraid you haven't copied & pasted the code across correctly.

That prompt reflects something that doesn't exist in my SQL.

I suggest you try again. If it fails again, copy in the SQL from your database again exactly as you did before, and include it in your next post.
Apr 23 '09 #15
Maybe this will help...I have multiple queries working on this form.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Add New Inventory Entry and Inventory Details].LedgerNumber, [Add New Inventory Entry and Inventory Details].SPDCaseNumber, [Add New Inventory Entry and Inventory Details].OfficerID, [Add New Inventory Entry and Inventory Details].ReceivedDate, [Add New Inventory Entry and Inventory Details].Location, Entrys.Comment, [Add New Inventory Entry and Inventory Details].ItemNumber, [Add New Inventory Entry and Inventory Details].EvidenceName, [Add New Inventory Entry and Inventory Details].Quantity, [Add New Inventory Entry and Inventory Details].LedgerID, [Add New Inventory Entry and Inventory Details].Notes, [Add New Inventory Entry and Inventory Details].[EvidenceDisposed?], Entrys.DispoDate, Entrys.DispositionMethod, Entrys.DispoCaseNumber, Entrys.Keep
  2. FROM Entrys INNER JOIN [Add New Inventory Entry and Inventory Details] ON Entrys.LedgerID = [Add New Inventory Entry and Inventory Details].LedgerID;
However, I understand that my mistake may be related to the "Print Current Record" button...what is the problem for the sub form of the list of Item #'s still not showing to be sorted correctly?
Apr 23 '09 #16
NeoPa
32,556 Expert Mod 16PB
Well, what can I say?

This looks nothing like what I posted.

The techniques I used are not here and it's displayed as an enormous dump of characters. I've tidied it up once to work with, I don't want to do it again thank you.

I'm not sure what you want from me. This is something totally different from what I suggested. How can I help if you choose to ignore what I suggest?

I admit to being a little confused.
Apr 23 '09 #17
NeoPa-

I am sorry to offend you...it appears that you are quite upset about my last post. I am not well versed in SQL or Access thus the posting for help. I was reviewing the queries that were associated with the form that I posted a screen shot of. I found that the "Print Current Form" had a seperate query and that is what I posted since the error as described above occurred when I clicked on the "Print Current Record" button.

I realize that you are a consumate contributor to this site and do apologize for my impotence regarding Access. However, if this is going to be resolving into a frustration for you and a curt response that is not needed then I thank you for your time and will drop the issue.

Anyone else willing to assist without the condensation?
Apr 23 '09 #18
NeoPa
32,556 Expert Mod 16PB
To be honest Adam, I was more confused than upset. I'm equally confused that you should interpret my quite reasonable post as condescension.

I simply asked you to post back the SQL from the query I thought I was helping you with. This is not a task that requires any previous Access or SQL expertise. Your previous experience should have no bearing on this whatsoever.

I was at a loss (confused) and I had no idea how to respond when I saw your post. This seemed to be entirely unconnected with what I'd asked for. How does someone explain that you got it so wrong without sounding insulting - bearing in mind this was nothing to do with experience or lack thereof? You try. Maybe you could have found better words than I did.

I'm happy to respect your wishes though, whatever reason that may be for.

I can simply wish you good luck with your project.
Apr 23 '09 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: D. Roshani | last post by:
Hello ! I wonder if any one can help me to create a cosomize sorting order (as Macro or added small program in c++ or c# which does this work) in a Access Database contaning one table only words...
6
by: Claudio | last post by:
Hi there, I am dealing with this "easy" C++ problem. Introduction Each number in a phone keyboard is associated to a set of tree chars.(i.e 2 = ABC). Programming Given 7 number in the...
1
by: MLH | last post by:
I have a challenge... In a table I call tblStuff4Letters with 3 fields: , and . I have a report called rptOutboundCorrespondence that feeds off this table. Sorting & grouping is turned on in...
28
by: Bailey.W87 | last post by:
my professor give me this assignment. Sort the R's B's and W's in an array. for example, the user enter: R B W W B B R W W R R W R B W i need to swap the characters in the array and arrange it...
3
by: ASP Developer | last post by:
I have a generic list of objects. These objects have a text field that contains a letter for the first character and numbers for the next three. For example, "A001". I need to sort these by...
16
by: Kittyhawk | last post by:
I would like to sort an Arraylist of objects on multiple properties. For instance, I have a Sort Index property and an ID property (both integers). So, the results of my sort would look like this:...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
4
by: arnuld | last post by:
This program follows from the section 6.5 of K&R2 where authors created a doubly-linked list using a binary-tree based approach. The only thing I have rewritten myself is the getword function. I am...
7
by: Totti | last post by:
Hi all, I am a newbie to javascript learning it for 2 months now, i am trying to make a sorter who will read english words from the one tex area or data file and show the result in the 2nd text...
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
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
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
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...
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.