[Last Call] Learn how to a build a cloud-first strategyRegister Now


How to sort characters in a specific order

Posted on 2012-08-16
Medium Priority
Last Modified: 2012-08-17
I have a pick sheet report that I want to sort a location field by a string field, but within that string field there is a date and and a quantity all entered in a specific order. So what I need to do is sort the date by year first, then month, and finally day. The date is entered in this format 08/16/12 (month/day/year) and right now it is sorting by month, day, year. So what I am wondering, is if there is way to tell Crystal in a formula to sort by specific character placements? Can I tell it to sort by the 7th character first, then the 8th, then the first, then the second and finally the fourth and fifth?
Question by:IsaacEin

Accepted Solution

Jason Schlueter earned 2000 total points
ID: 38302377
Give this a try as a formula:
stringvar sort1 := mid({Table.String},7,1);
stringvar sort2 := mid({Table.String},8,1);
stringvar sort3 := mid({Table.String},1,1);
stringvar sort4 := mid({Table.String},2,1);
stringvar sort5 := mid({Table.String},4,1);
stringvar sort6 := mid({Table.String},5,1);

stringvar sortall := sort1 + sort2 + sort3 + sort4 + sort5 + sort6;

Open in new window

Then sort by that formula.
LVL 18

Expert Comment

ID: 38302640
You can create a SQLExpression like this :

The syntax is for SQLServer and will convert values like '08/16/12' to '2012/08/16'
Sort by the SQLExpression.
LVL 101

Expert Comment

ID: 38303340
I think you need to get the left 8 characters before converting to a date


Sort on that formula

LVL 35

Expert Comment

ID: 38303714
FWIW, if you want to use a formula like the one that JasonSchlueter suggested, you could shorten it to:

stringvar sort1 := mid({Table.String},7,2);
stringvar sort2 := mid({Table.String},1,2);
stringvar sort3 := mid({Table.String},4,2);

stringvar sortall := sort1 + sort2 + sort3


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month18 days, 11 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question