I have problem when i'm using a condition for checking null values in report. My condition is
$F{BILANGAN4}==0 ? "-" : ""
The values of field does not appear but it just appear "-".
Anyone know about this?
I'm not sure what $F{BILANGAN4}==0 ? "-" : "" will compile-down to. Have you looked at the generated .java code for your report? java.lang.Long could be null, so you want to check like this:
( ( null == $F{BILANGAN4} || $F{BILANGAN4} == 0 ) ? "-" : "" )
I usually explicitly add .longValue() to calls like that just to be explicit: I'll get a compiler failure if the type isn't correct and I know I need to adjust something and maybe re-consider the code.
Note that the above code (as a text-field value for instance) will only display "-" or nothing. If you want the value of the $F to actually display, you'll have to put it in there. I'm fairly sure this is actually what you want:
( ( null == $F{BILANGAN4} || $F{BILANGAN4} == 0 ) ? "-" : $F{BILANGAN4} )
Related
I'm using CASE expression to display "NamaAyah" or "NamaIbu" or "NamaWali", and if all of them is empty, the default value will display "ORTU-'NomorPokok' ".
But the default value not displayed, it just displays symbol "-" in my table. I think the value in ELSE statement not executed.
Postgre Version : PostgreSQL 9.4.15
This is my code
SELECT
"MahasiswaID" AS "PERSONID","NomorPokok" AS "KODE",
UPPER(CASE
WHEN "NamaAyah" <> '' THEN "NamaAyah"
WHEN "NamaIbu" <> '' THEN "NamaIbu"
WHEN "NamaWali" <> '' THEN "NamaWali"
ELSE 'ORTU'||'-'||"NomorPokok"
END) AS "NAMALENGKAP"
FROM "MasterMahasiswa" ORDER BY "KODE"
and this is the result
The expression you have can simpler be:
ELSE 'ORTU-'||"NomorPokok"
Apart from that, the only reasonable explanation for what you display is that there are literal - in one or more of your columns "NamaAyah", "NamaIbu" and "NamaWali". Did you check that?
So, I'm much more familiar with Transact-SQL than I am with Crystal formulas. What I would like to do is convert something like the following SQL where clause to be used in Crystal to conditionally suppress a section:
.
.
.
AND (osAddressUse.Description <> 'Conservator Address'
OR (
ISNULL(bcDocumentDetail.PrimaryStreet,'') = ISNULL(osaddress.PrimaryStreet,'')
AND
ISNULL(bcDocumentDetail.SecondaryStreet,'') = ISNULL(bcDocumentDetail.SecondaryStreet,'')
)
)
.
.
.
Basically, the section should only display if the osAddressUse.Description = "Conservator Address" OR both the Primary Street and Secondary Street within both tables bcDocumentDetail and osAddress are not identical.
What I came up with so far is the following, but it doesn't work 100% of the time:
{osAddressUse.Description} <> "Conservator Address"
OR
( {bcDocumentDetail.PrimaryStreet} = {osAddress.PrimaryStreet}
AND
{bcDocumentDetail.SecondaryStreet} = {osAddress.SecondaryStreet} )
There are some situations where the data in these fields can either be NULL or "". If it's a NULL value, I want it converted to "", that way, they technically match, and the section will be suppressed.
Nevermind. I was able to figure it out:
TRIM ({osAddressUse.Description}) <> "Conservator Address"
OR
(
(IF ISNULL({osAddress.PrimaryStreet}) THEN "" ELSE {osAddress.PrimaryStreet})
= (IF ISNULL({bcDocumentDetail.PrimaryStreet}) THEN "" ELSE {osAddress.PrimaryStreet})
AND
(IF ISNULL({osAddress.SecondaryStreet}) THEN "" ELSE {osAddress.SecondaryStreet})
= (IF ISNULL({bcDocumentDetail.SecondaryStreet}) THEN "" ELSE {osAddress.SecondaryStreet})
)
I have a where clause like this:
Where m.Date_6 = Case When #IsCurrentRequest = 1 Then NULL Else m.Date_6 End
#IsCurrentRequest is a bit parameter. I want to check if #IsCurrentRequest = 1 then return m.Date_6 is NULL otherwise return 1. I know this won't work because m.Date_6 = NULL is not working. How do I fix? thanks!
I am not sure I understood correctly your question, but may be this condition is what you are looking for (without using CASE)?
WHERE #isCurrentRequest=1 AND m.date_6 IS NULL OR #isCurrentRequest=0
Anyway, when checking if a value is NULL, you can't use column_name=NULL, but you should use column_name IS NULL (as NULL is a "particular" value)
The = operator will return NULL if any of its operands is NULL, therefore your code will not work as intended.
Try something like this:
WHERE IIF( #IsCurrentRequest = 1, IIF( m.Date_6 IS NULL, 1, 0 ), 1)
I have an XML documents which include 3 titles.
<page>
<title>
<title>
<title>
Now I want to show them in one text field. I do the following
$F(title)+","+$F(title2)+","+$F(title3)
and it works well. There is a problem if title2 and title3 will be empty. assume if title2 is empty in XML than the result is being like blow:I
This is the title 1 ,,This is title 3
is there suggestion for this?
Something like this should work:
($F{title} != null ? $F{title} : "" )
+ ($F{title2} != null ? ", " + $F{title2} : "")
+ ($F{title3} != null ? ", " + $F{title3} : "")
This is assumes that:
a) empty means null
b) field $F{title} will never be null
If I am wrong on assumption (b) this the expression gets only a little more complex. It can be done.
I'm working on a report in Crystal Reports XI that allows someone to filter help desk tickets using a number of optional dynamic parameters. If I make a selection for each parameter it returns the expected results, but if I leave out any of the parameters it doesn't return anything and when I look at the SQL query it says, "No SQL Query is used because the record selection formula returns no records." I currently have the following code for Record Selection:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
)
and
If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
)
and
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
)
and
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
)
To me, this seems like it should work and if I leave out the If statement to verify the parameters have values I get an error so it seems like the HasValue is working properly. Any ideas?
Your problem stems from not explicitly handling the optional parameter configurations. It's easy to run into this problem when using if-statements in the record selection formula. Instead, explicitly handle the cases where the parameters DO and DO NOT have values. Something like this:
...
(not(hasvalue({?Group})) or {Groups.Code}={?Group})
and
(not(hasvalue({?Category})) or {Incident.Subject Description} = {?Category})
and
(not(hasvalue({?Staff})) or {Incident_Details.Login ID} = {?Staff} )
and
(not(hasvalue({?Community})) or {Incident.Company Name} = {?Community})
Doing it this way effectively tells CR to just ignore the parameter if is doesn't have a value, otherwise select records based on what was entered in those parameters.
The Record Selection formula indicates whether a record must be used, or not, by returning true or false. With that in mind, if some value is informed, the formula must return True if it meets some criteria. If nothing is informed on the filter, the formula must always return True.
Try something like this:
{Incident.State:} = "C" and
{Incident.Close Date & Time} in {?BDate} to {?EDate} and
(If HasValue({?Group}) Then (
{Groups.Code} = {?Group}
) else
(True))
and
(If HasValue({?Category}) Then (
{Incident.Subject Description} = {?Category}
) else
(True))
and (
If HasValue({?Staff}) Then (
{Incident_Details.Login ID} = {?Staff}
) else
(True))
and (
If HasValue({?Community}) Then (
{Incident.Company Name} = {?Community}
) else
(True))