• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 504
  • Last Modified:

Crystal Reports 2008 - First position in field is " "

Hi and thanks,

I have this code:
If {TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress} > "" Then
Left({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}, Instr({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}, " ") -1)
Else "";

This works fine until there is a bland in the first position of the field Example:

|1234 Church Street| <== this works fine and gives me |1234|
| 1234 Church Street| <=== This give me a return that is blank

Also:
I would like to find the formula for:
|1234 Church Street| = |Church Street|

Thanks
0
Amour22015
Asked:
Amour22015
3 Solutions
 
Jared_SCommented:
This should take care of your blank value:

If {TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress} > "" Then 
Left(LTRIM({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}), Instr(LTRIM({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}), " ") -1)
Else "";

Open in new window

0
 
CodeCruiserCommented:
Should

If {TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress} > "" Then

not be

If {TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress} <> "" Then
0
 
mlmccCommented:
Does the text always have the | | around it or did you add those for clarity?

mlmcc
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Amour22015Author Commented:
mlmcc,
added || for clarity
0
 
mlmccCommented:
You could also use

If IsNull({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}) OR Trim({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}) = ""  THEN
   ""
Else
    Split(Trim({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress})," ")[1]

mlm
0
 
James0628Commented:
For your other question, to get the part of the string after the first space, you could use:

if InStr (Trim ({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}), " ") > 0 then
  Mid (Trim ({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}),
   InStr (Trim ({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}), " ") + 1)
else
  {TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}


 Or, you could use a variable to eliminate the repeated Trim functions:

Local StringVar str;

str := Trim ({TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress});

if InStr (str, " ") > 0 then
  Mid (str, InStr (str, " ") + 1)
else
  {TEMP_PWC_Sales_Report_SP_MAIN.OwnerAddress}


 In each formula, the last line, after the "else", is what you want the formula to produce if the field doesn't contain any embedded spaces.  For example, if it was just "Church", would you want to see the original field ("Church"), or nothing, or something else?  Change that last line accordingly.

 I am assuming that the field won't be null, or the report is set to convert nulls to default values.  If not, you'll need to use IsNull to handle them.

 James
0
 
Amour22015Author Commented:
Thanks for all your help...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now