Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Sorting ODBC or whatelse Post Reply Post New Topic
Author Message
besando
Newbie
Newbie


Joined: 24 Jan 2013
Online Status: Offline
Posts: 2
Quote besando Replybullet Topic: Sorting ODBC or whatelse
     Posted: 24 Jan 2013 at 5:09am
Hi all, i have some problem with the select expert, or the odbc sort, or whatelse.

E.g.

I have in my db table (as400 ebcdic) these records (in this order):

AA
AAAA11
AAAA12
AAAA12C
AA005
AA1

I want to display all the records with my code (char 15) less than
 "AA1" so my record selection formula is {myfile.mycode} < "AA1"

but the result of the query is

AA
AA005

Why?

I have tried with excel using the same ODBC but the result was correct, just in my Crystal XI the result is not what i want.

As anyone suggestions?
Thanks

Corrado


IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Jan 2013 at 5:50am

why?

because the it is comapring each value in the set to see if it it is < "AA1" and only those two values meet that condition. It is not looking to see which rows "exist prior to" "or "above" the AA1 row.
Using < and > on strings can be very tricky and I do not know all the rules about how it interprets the values in relation to each other.
As for suggestions, what do you really want it to do? Show rows that exist prior to the AA1 row based on how the rows are inserted into the DB? Or do you have a way that you are interpretting the letter values that you can convert this to some formula that enforces your logic?
IP IP Logged
besando
Newbie
Newbie


Joined: 24 Jan 2013
Online Status: Offline
Posts: 2
Quote besando Replybullet Posted: 24 Jan 2013 at 6:24am
Thanks for the answer but maybe my question is not explained very well.

If i have a table with records ordered like this:
A
AA
AB
AC
B
BA
BB
BC
C
CA
CB
CC
.. and so on.

I want to select the records where the value is greater than B and less than C.  I write a select * from table where code > "B" and code < "C"  and ther results are all the codes between B and C.

The problem is when crystal do the select records.

These are the records ordered not the records sequence in the file.

AA
AAAA11
AAAA12
AAAA12C
AA005
AA1


So if my select is select * from table where code < "AA1"  AAAA12should be a selected record.






Edited by besando - 24 Jan 2013 at 6:25am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Jan 2013 at 7:35am
so you are sorting ascending on the field and since it sorts in a particluar sequence you expect that if you use a a < or > it would return values comaprible to the sort, correct?
I do not know what the rules are in terms of using < and > on strings but I they never match my expecations using a alpha sort.
If you look in Crystal Help under the StrCmp function you will see examples of this.
On your current report stick a formula field in as
strcmp({myfile.mycode},next({myfile.mycode}))
You will get avalues of -1 (the row is < the next row), 0 (the row = the next row) and 1 (the row is > the next row). YOu will see it doe snot follow the same logic as alpha sorting.
 
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum