Sorting Records in Crystal Reports

Hi,

I have an issue with sorting records alpha numerically in Crystal. I'm not sure it's Crystal as much as the way we have coded our back end MSSQL database.

We have reference numbers which are like this:

AA1
AA2
AA3
AA4
AA5
AA6
AA7
AA8
AA9
AA10
AA11
AA12 - and so on...

What is happening in sorting my records is this:

AA1
AA10
AA11
AA12
AA2
AA3
AA4 and so on...

Is there a way to sort these in proper alpha numerical order even if a formula has to be used? It's creating a nightmare with my reports.

Any help would be much appreciated.

Best Regards,

Ken

AA11
kenuk110Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peter57rCommented:
Do all values start with two letters?
What is the longest number?
Assuming 2 letters followed by up to 4 digits then...


Left({table.field},2}) & right("0000" & mid({table.field},3), 4)

0
kenuk110Author Commented:
Hi,

We used a spreadsheet type coding system so to answer your question, no, they can be like this:

A1
A10
AA1
AA10

I know I know, it's a stupid way to code things! they are never more than 2 aplha and 2 numeric though.

Is it still possible to do this with what you have suggested?

Cheers
0
kenuk110Author Commented:
I tried to input the suggested code but I'm not sure where to put it, I went in to Group Expert then selectd the field that I want to sort, selected 'group by formula' but it won't let me select the table.field I need to use. Am I going to the wrong place?
0
peter57rCommented:
It'll be a bit more involved then.
You have to create a new formula field.  You can't adjust what's already there.
Then sort on the formula field.

If {table.field}[2] in ("0" to "9") then
Left({table.field},1}) & right("00" & mid({table.field},2), 2)
else
Left({table.field},2}) & right("00" & mid({table.field},3), 2)

0
mlmccCommented:
Since you have some 1 letter and some 2 letter values, the formula won't work.

If you are just trying to sort, you use the RECORD SORT not the GROUP EXPERT

Try this
Create a formula
Local StringVar SortField;
Local NumberVar Index;
SortField := {Table5.myId}[1];
If {Table5.myId}[2] >= 'A' then
(
   SortField := SortField & {Table5.myId}[2];
   SortField := SortField & Right("00" & Mid({Table5.myId},3),2);
)
Else
   SortField := SortField & Right("00" & Mid({Table5.myId},2),2);
SortField

Use the formula in the record sort expert as the sort field

mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.