Re: Sorting Alpha then Numeric
- From: John Melbourne <JohnMelbourne@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 14 Jun 2007 22:39:00 -0700
Hi Chuck,
I finally got it thanks for the help.
I had to convert the chars, I used Asc([X]) and if numeric add 123, I also
had to test the length as not all had 6 chars.
First field enter:
SRT1: IIf(Left([X],1)>="0" And Left([X],1)<="9",Asc([X])+123,Asc([X]))
SRT2: IIf(Len([X])>1,IIf(Mid([X],2,1)>="0" And
Mid([X],2,1)<="9",Asc(Mid([X],2,1))+123,Asc(Mid([X],2,1))),0)
SRTJ3: IIf(Len([X])>2,IIf(Mid([X],3,1)>="0" And
Mid([X],3,1)<="9",Asc(Mid([X],3,1))+123,Asc(Mid([X],3,1))),0)
SRTJ4: IIf(Len([X])>3,IIf(Mid([X],4,1)>="0" And
Mid([X],4,1)<="9",Asc(Mid([X],4,1))+123,Asc(Mid([X],4,1))),0)
SRTJ5: IIf(Len([TBLF01FAC])>4,IIf(Mid([TBLF01FAC],5,1)>="0" And
Mid([TBLF01FAC],5,1)<="9",Asc(Mid([TBLF01FAC],5,1))+123,Asc(Mid([TBLF01FAC],5,1))),0)
SRTJ6: IIf(Len([X])>5,IIf(Mid([X],6,1)>="0" And
Mid([X],6,1)<="9",Asc(Mid([X],6,1))+123,Asc(Mid([X],6,1))),0) AS SRTJ6
--
John Melbourne
"Chuck" wrote:
On Wed, 13 Jun 2007 21:41:02 -0700, John Melbourne.
<JohnMelbourne@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I need to sort my report Alpha before Numeric I managed to sort by the first
position by useing the Val(left(sort,1) this made a column of 0 for alpha and
the number in first position, so it sorted OK but second position did not.
hope this makes sence. what I want to do is sort
A
|
z
1
|
2
So if I have
AAAA
AZZZ
A1AA
BAAA
BZZZ
B1AA
B999
Any help welcome.
My operating system is XP Professional Ver 2002 SP2.
I'm using Access 2003.
Just realized that Numeric data can be in the last 3 places.
You will need three blank fields and enter 3 sort order equations
First field enter:
SRT1: IIf((Mid([X],4,1)>="1" And Mid([X],4,1)<="9"),Left([X],3) & "_",[X])
Second field enter:
SRT2: IIf((Mid([X],3,1)>="1" And Mid([X],3,1)<="9"),Left([X],2) & "_" &
Right([X],1),[X])
Third field enter:
SRT3: IIf((Mid([X],2,1)>="1" And Mid([X],2,1)<="9"),Left([X],1) & "_" &
Right([X],2),[X])
Sort each field ascending.
The order of the fields is important.
The SQL statement is:
SELECT Table1.X, IIf((Mid([X],4,1)>="1" And Mid([X],4,1)<="9"),Left([X],3) &
"_",[X]) AS SRT1, IIf((Mid([X],3,1)>="1" And Mid([X],3,1)<="9"),Left([X],2) &
"_" & Right([X],1),[X]) AS SRT2, IIf((Mid([X],2,1)>="1" And
Mid([X],2,1)<="9"),Left([X],1) & "_" & Right([X],2),[X]) AS SRT3
FROM Table1
ORDER BY IIf((Mid([X],4,1)>="1" And Mid([X],4,1)<="9"),Left([X],3) & "_",[X]),
IIf((Mid([X],3,1)>="1" And Mid([X],3,1)<="9"),Left([X],2) & "_" &
Right([X],1),[X]), IIf((Mid([X],2,1)>="1" And Mid([X],2,1)<="9"),Left([X],1) &
"_" & Right([X],2),[X]);
Most likely the three sort fields can be combined into a single field with a
little work.
Just a wizard prodder
Chuck
--
- Follow-Ups:
- Re: Sorting Alpha then Numeric
- From: Chuck
- Re: Sorting Alpha then Numeric
- References:
- Re: Sorting Alpha then Numeric
- From: Chuck
- Re: Sorting Alpha then Numeric
- Prev by Date: Re: Sorting Alpha then Numeric
- Next by Date: Not sure if report is closed
- Previous by thread: Re: Sorting Alpha then Numeric
- Next by thread: Re: Sorting Alpha then Numeric
- Index(es):
Relevant Pages
|