Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Sort using CStr when negative Post Reply Post New Topic
Author Message
KellyL250
Newbie
Newbie


Joined: 27 Nov 2009
Location: United States
Online Status: Offline
Posts: 8
Quote KellyL250 Replybullet Topic: Sort using CStr when negative
     Posted: 10 Dec 2009 at 11:56pm
I have to sort a report based on a parameter.  Unfortunately the sort options are of different data types.  One is string and one is money.
I have created a Formula Field and identified it as the Sort Field.
 
IF {?SortBy} = "ITEM" THEN {tbHISTORY.ITEM_NO}
ELSE  CStr({@Excess},2)
 
?SortBy is the parameter field coming in from vb.
 
It works fine except that it is sorting by the absolute value of @Excess thereby mixing positive and negative numbers together.
 
1000.00
-1050.00
1100.00
 
Anyone have a way around this?  Converting the Item_No is not an option as it is alphanumeric.
 
Thanks in advance.
 
Larry
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 Dec 2009 at 7:23am
IF {?SortBy} = "ITEM" THEN
  {tbHISTORY.ITEM_NO}
ELSE 
  IF {@Excess} < 0 THEN  
    " "+CStr({@Excess},2)
  ELSE
    CStr({@Excess},2)
 
I wonder if this will work.  You can also try removing the ,2 as it shouldn't be necessary in a sort.  The other question that pops to mind is what is the formula returning...it is returning an absolute value?
 
To trouble shoot, I would drop the Sort formula on the report and see what is being displayed, that might help you track down what is going on.
 
HTH
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 Dec 2009 at 8:17am
Another option that I think will work...
You can make 2 formula fields as your sorting options.
@Sort1
IF {?SortBy} = "ITEM" THEN {tbHISTORY.ITEM_NO} ELSE  'A'
@Sort2
IF {?SortBy} = "AMOUNT" THEN {table.moneyfield} else 0
 
In your sort add @sort1 as the primary and @sort2 as the secondary sort.
IP IP Logged
KellyL250
Newbie
Newbie


Joined: 27 Nov 2009
Location: United States
Online Status: Offline
Posts: 8
Quote KellyL250 Replybullet Posted: 11 Dec 2009 at 9:23am
The two sort fields works like a charm.  Thanks so much.
 
The other solution offered worked except that it presented the negative numbers in inverse order.
 
Thanks again for your responses.
 
Larry
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