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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ordering

Status
Not open for further replies.

emuye

MIS
Aug 23, 2004
41
US
Is it possible to sort records with alphabets and numbers first followed by records with numbers .for example a1,a2,b1,b2 and 11 and .if someone has a clue on how i handle this, please let me know.I am using CR 8.5 and the selected field is a string.
 
You could write a formula field for sorting, something like

if {yourval} < "a" then "ZZ " & {yourval}
else {yourval}

You don't need to actually show this value, just sort using it.

Madawc Williams (East Anglia)
 
You might also want to ensure an accurate numerical sort by adapting Madawc's formula to something like:

if {table.string} < "a" then
"Z" + totext(val({table.string}),"0000") else
left({table.string},1) + totext(val(mid({table.string},2)),"0000")

This assumes that the field always starts with one letter that is not "Z" and that the numbers range up to 9999. You can adjust accordingly.

-LB
 
my record has a value from a1,a2,b1......z1, 11,12,154 etc.How could i handle when i come across into this kind of situations.Do you think the above formula will work at any circumstance?
thank you
 
I don't know what "Is it possible to sort records with alphabets and numbers first followed by records with numbers" means.

Alphabets and numbers first followed by records with numbers? Something is lost in translation here.

Your post lacks technical inforamtion, generally if your post is a quick blurb, you're not supplying enough information. Consider if you were working on the problem, you'd probably ask:

Crystal version *you supplied this
Database/connectivity used
Example data
Expected output

Here's an example on how to sort on a field which has both alpha and numeric by creating 2 formulas:

// Numeric portion
whileprintingrecords;
Stringvar TheNum;
numbervar x;
For x := 1 to len({@nameid}) do(
if isnumeric(mid({@nameid},x,1)) then
TheNum:= TheNum+ mid({@nameid},x,1)
);
val(TheNum)

// Alpha portion
whileprintingrecords;
Stringvar TheAlpha;
numbervar x;
For x := 1 to len({@nameid}) do(
if not(isnumeric(mid({@nameid},x,1))) then
TheAlpha:= TheAlpha+ mid({@nameid},x,1)
);
TheAlpha

Now you can add these 2 to the Report->Sort Records in whichever order you want the rows sorted.

Keep in mind that if you have groupings, you'll want to reset this value in the group header using a formula such as:

whileprintingrecords;
Stringvar TheAlpha:="";
Stringvar TheNUm:=""

Hope this helps to resolve.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top