Apr 12, 2006 #1 Spruce4U Technical User Feb 1, 2006 23 CA This may sound like a very basic question, but how to make Access sort properly a column of numbers? For example, instead of logically sorting my records like the following: 1 2 3 4 5 6 7 8 9 10 11 12 Access sorts them like this: 1 10 11 12 2 3 4 5 6 7 8 9
This may sound like a very basic question, but how to make Access sort properly a column of numbers? For example, instead of logically sorting my records like the following: 1 2 3 4 5 6 7 8 9 10 11 12 Access sorts them like this: 1 10 11 12 2 3 4 5 6 7 8 9
Apr 12, 2006 #2 belovedcej Programmer Nov 16, 2005 358 US Your field is probably text instead of integer. If it is integer, it will sort properly. If it is text, you will need to have leading zeros. Upvote 0 Downvote
Your field is probably text instead of integer. If it is integer, it will sort properly. If it is text, you will need to have leading zeros.
Apr 12, 2006 Thread starter #3 Spruce4U Technical User Feb 1, 2006 23 CA It is a calculated field in a query and I have put the format 'general number' to it. Do you have any more clues? Upvote 0 Downvote
It is a calculated field in a query and I have put the format 'general number' to it. Do you have any more clues?
Apr 12, 2006 #4 belovedcej Programmer Nov 16, 2005 358 US Hmm - I'm a little stumped on that. I looked around for some clues - maybe try casting it as a long? CLng(nameOfField) Unless you want decimal points - then CDbl(nameOfField) I don't tend to use access calculated fields, so I'm guessing, too. Upvote 0 Downvote
Hmm - I'm a little stumped on that. I looked around for some clues - maybe try casting it as a long? CLng(nameOfField) Unless you want decimal points - then CDbl(nameOfField) I don't tend to use access calculated fields, so I'm guessing, too.
Apr 12, 2006 #5 PHV MIS Nov 8, 2002 53,708 FR Have a look at the Val function. Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886 Upvote 0 Downvote
Have a look at the Val function. Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
Apr 12, 2006 Thread starter #6 Spruce4U Technical User Feb 1, 2006 23 CA PHV, Thanks but actually, the calculated field uses the Val function already. belovedcej, thanks for the comments. Upvote 0 Downvote
PHV, Thanks but actually, the calculated field uses the Val function already. belovedcej, thanks for the comments.
Apr 12, 2006 #7 PHV MIS Nov 8, 2002 53,708 FR Any chance you coukd post your actual SQL code ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886 Upvote 0 Downvote
Any chance you coukd post your actual SQL code ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
Apr 12, 2006 Thread starter #8 Spruce4U Technical User Feb 1, 2006 23 CA PHV, Here is the SQL code for 2 calculated fields, the second one (col) giving the sorting problems. IIf([pos_sur_plaque]<>"",Left([pos_sur_plaque],1),"") AS row IIf([row]<>"",Val(Replace([pos_sur_plaque],[row],"")),"") AS col where: [pos_sur_plaque] is an alphanumeric chain in the style of "A01", "A02", "G12" etc. The "row" calculation gets the first character (here "A", "G", etc.) The "col" calculation converts the rest ([pos_sur_plaque] with "row" removed) to a number format using the 'Val' function. Upvote 0 Downvote
PHV, Here is the SQL code for 2 calculated fields, the second one (col) giving the sorting problems. IIf([pos_sur_plaque]<>"",Left([pos_sur_plaque],1),"") AS row IIf([row]<>"",Val(Replace([pos_sur_plaque],[row],"")),"") AS col where: [pos_sur_plaque] is an alphanumeric chain in the style of "A01", "A02", "G12" etc. The "row" calculation gets the first character (here "A", "G", etc.) The "col" calculation converts the rest ([pos_sur_plaque] with "row" removed) to a number format using the 'Val' function.
Apr 12, 2006 #9 PHV MIS Nov 8, 2002 53,708 FR ORDER BY Val(Mid([pos_sur_plaque],2)) Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886 Upvote 0 Downvote
ORDER BY Val(Mid([pos_sur_plaque],2)) Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886