Amerilab
asked on
crystal display string
I just want to add a asterisk on the end of a string value if it meets a criteria and if it doesn't I want to return the original value. Here is my code under display string for the field I am working on. What happens is that the else statement return blank.
if {Command.RECIPE_LINES_PART _CODE} <> "" then
{Command.PART_CODE}+ "*"
else ({Command.PART_CODE})
if {Command.RECIPE_LINES_PART
{Command.PART_CODE}+ "*"
else ({Command.PART_CODE})
ASKER
yes it does. When I put in the code it blanks out the one that doesn't meet the first criteria.
Tried it same result.
Tried it same result.
That's odd. The code basically says: If field 1 exists, then concatenate field 2 with * otherwise field 2 by itself. You're saying field 2 exists in this scenario, even if field 1 doesn't?
1) Is all the code in a single command or are there multiple commands/table joins?
2) Are you running this comparison in the detail section of the report or in a header/footer?
~Kurt
1) Is all the code in a single command or are there multiple commands/table joins?
2) Are you running this comparison in the detail section of the report or in a header/footer?
~Kurt
ASKER
I am running it right on the field in the report. If I have nothing in the display string code then all data comes up. But when I put it back in the report only show some of the data. The data that meets the first criteria.
Add WhilePrintingRecords; as the first line.
If you don't use that it may evaluate it early.
mlmcc
If you don't use that it may evaluate it early.
mlmcc
Instead of using the display string formula add a new formula and place thsi and teh 2 fields recipe_lines_part_code and part_code onto your report and show us a screenshot of teh report indicating which records are returning the wrong results.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
go to File->Report Options.
Select "Convert Database NULL values to default" and "Convert otjer NULL values to default" . This will replace your null values with proper values i.e. NULL string with "" and NULL integer with 0.
Select "Convert Database NULL values to default" and "Convert otjer NULL values to default" . This will replace your null values with proper values i.e. NULL string with "" and NULL integer with 0.
msd1305 has a good point. If nulls are the problem, that would be another way to handle this. Actually, it's what I would usually do for something like this. I guess I was too focused on the formula to think of it. :-)
James
James
Amerilab, dont u think u should have accepted my comment as the solution??
ASKER
Yes. I apologize. I accepted the wrong one. Is there anyway to change this?
ASKER
How do I change the accepted answer?
If anything, I suggest you split points between at least James and msd1305. The issue, based on your acceptance, was obviously due to NULLs. James corrected the syntax in my original suggestion, which accounted for both NULLs and empty strings. MSD1305's converts NULLs to empty strings - both accomplish the same thing.
Regardless, I actually recommend against converting NULLs to empty strings. There's a specific scenario in which Crystal Reports will erroneously filter out records based on that setting. It involves having parameter against the field that contains NULL values. That specific scenario may not apply to this report, but it's good to know about as a "best practices" rule of report design (the issue has existed in every version of Crystal Reports since at least 8 - 2008). Here are some links that demonstrate the problem:
https://www.box.net/shared/yd65ff3k8h (sample report)
https://docs.google.com/present/view?id=ddcfj5p5_78fbcxb9cz (explained in this presentation from the 2009 conference)
~Kurt
Regardless, I actually recommend against converting NULLs to empty strings. There's a specific scenario in which Crystal Reports will erroneously filter out records based on that setting. It involves having parameter against the field that contains NULL values. That specific scenario may not apply to this report, but it's good to know about as a "best practices" rule of report design (the issue has existed in every version of Crystal Reports since at least 8 - 2008). Here are some links that demonstrate the problem:
https://www.box.net/shared/yd65ff3k8h (sample report)
https://docs.google.com/present/view?id=ddcfj5p5_78fbcxb9cz (explained in this presentation from the 2009 conference)
~Kurt
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
If
(
Not (IsNull({Command.RECIPE_LI
OR {Command.RECIPE_LINES_PART
)
Then
//as a force of habit, I alway use an ampersand to concatenate objects, since the + only works between strings, but & works with all datatypes
{Command.PART_CODE} & "*"
Else
{Command.PART_CODE}
Also, have you verified that {Command.PART_CODE} really has data for the records in question?
~Kurt