Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Replace InputString with some value Post Reply Post New Topic
Author Message
Douang
Newbie
Newbie


Joined: 15 Nov 2011
Location: United States
Online Status: Offline
Posts: 12
Quote Douang Replybullet Topic: Replace InputString with some value
     Posted: 05 Jul 2012 at 9:27am

 I am working on CR11 and I have a formula field.  In the formula field, I want to replace the InputString with (*) asterisk when InputString has literal "No Fuel" in it.

 My formula looks like this:
 Replace ({WPRoute_vw_ProductivityReport.RouteNote}, "NO FUEL", "*")
 
 It does not work for me.
 
 Help!
 
 Thanks!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Jul 2012 at 9:43am

depends. not sure if you need to change a whole long string or just some text within it.

first replace() is by default case sensitive.
to make it case-insensitive use
replace({WPRoute_vw_ProductivityReport.RouteNote} ,'NO FUEL','*',1,-1,1)
 
if you want to change a whole long string that might have the phrase you can use a LIKE or instr() function rather than replace() ...
if {WPRoute_vw_ProductivityReport.RouteNote} like '*NO FUEL*' then
'*' else {WPRoute_vw_ProductivityReport.RouteNote}


Edited by DBlank - 05 Jul 2012 at 9:45am
IP IP Logged
Douang
Newbie
Newbie


Joined: 15 Nov 2011
Location: United States
Online Status: Offline
Posts: 12
Quote Douang Replybullet Posted: 05 Jul 2012 at 9:54am
 I tried your suggestion with IF statement:
 
if {WPRoute_vw_ProductivityReport.RouteNote} like '*NO FUEL*' then '*' else {WPRoute_vw_ProductivityReport.RouteNote}
 
The InputString = "No fuel"
 
Is this case-sensitive?
 
 
The result of the report shows "N".  Is it because it takes only the first character of "No fuel"?
 
 




Edited by Douang - 05 Jul 2012 at 9:57am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Jul 2012 at 9:57am
LIKE is not case sensitive
 
try expanding your result field.
 
 
also what is some sample data from that field?


Edited by DBlank - 05 Jul 2012 at 10:00am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 05 Jul 2012 at 10:02am
you can also create a different formual field for some testing,
use
{WPRoute_vw_ProductivityReport.RouteNote} like '*NO FUEL*'
 
 and place it on your detail row to see a true/false evaluation.
when it is true your other formual should return a *, whne it is false it should return the original field value.
IP IP Logged
Douang
Newbie
Newbie


Joined: 15 Nov 2011
Location: United States
Online Status: Offline
Posts: 12
Quote Douang Replybullet Posted: 05 Jul 2012 at 10:06am
Expanded the result field.
 
Now the result shows "No fuel" instead of (*) asterisk on the record that has literal "No fuel".
 
The IF statement falls into ELSE statement.
 
Some sample data from that field is "No fuel ", "no fuel", NULL/BLANK,"downtime", etc.
 
Thank you for your help!
IP IP Logged
Douang
Newbie
Newbie


Joined: 15 Nov 2011
Location: United States
Online Status: Offline
Posts: 12
Quote Douang Replybullet Posted: 05 Jul 2012 at 10:13am
Creating another formula field as you suggested WORKS!
 
THANK YOU!
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