Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort (order) a field that is a combination of alpha & number 1

Status
Not open for further replies.

jpkeller55

Technical User
Apr 11, 2003
131
US
I have a field of data that is a combination of letter and number and I cannot figure out how to get it ordered correctly.

This is how it is sorting now:
KeyNum
A1
A2
A3
B1
B10
B11
B2
B3[/color red]

I would like to get it to sort like this:
KeyNum
A1
A2
A3
B1
B2
B3
B10
B11[/color blue]


I am guessing I need to split the field into letter and number and sort but don't know how to do that.

Thanks, Jim

 
How about:
SELECT Field1
FROM Table
ORDER BY Left([Field1],1), Val(Mid([Field1],2));
 
In a new query create two new fields put this code in.

First:Left([FieldName],1)
Second:iif(Count([FieldName]> 2, Right([Field],1), Right([Field], 2))

Try this if the iif is backward just switch the rights around. Then use your sort on these 2 fields.

I hope this helps :)
 
Shirley, thanks for your idea too. I will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top