Crystal reports selecting record that contain empty strings or "null" - crystal-reports

I have a report that for a field called JobNo there are some records that have "null" as the the cell value and some that have an empty string "". there is another field called AccntNo that im also selecting by in the same selection formula.
This is what i have tried without success in the selection formula for crystal reports.
{accnt.accno} = "7015" and
{accnt.jobno} = "" or {accnt.jobno} isnull
any help is apreciated

Selection formula doesn't work as expected, sometimes.
I suppose that this will work
{accnt.accno} = "7015" and
( isnull({accnt.JobNo}) or {accnt.jobno} = "" )
First of all I put parenthesis on 'or' clause.
But, the strangest thing, is that isnull clause must be evaluated before other comparison clauses.

Related

An access query comparing the time part in a date field with values input in a form

I have an access query with predicates (conditions) on a date/time column called start_time. The condition is on two form fields defined with "Format" as "short time". The problem is that this query does not give correct results.
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm")
BETWEEN [Forms]![CustEventRptForm]![FromHour]
AND [Forms]![CustEventRptForm]![ToHour]
Also tried it using Format([start_time], "short time") BETWEEN ... - did not work either.
Do we need anything in addition to above code to get the correct results?
I have tested with literal values as shown below and I get correct results with that.
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm") BETWEEN '10:00' AND '13:00'
My guess is it's not interpreting the value from the form correctly.
Try adding quotes before and after the values:
SELECT event_cust.*
FROM event_cust
WHERE Format([start_time],"hh:mm") Between "" & [Forms]![CustEventRptForm]![FromHour] & ""
And "" & [Forms]![CustEventRptForm]![ToHour] & ""
Don't use string comparisons for date/times.
SELECT event_cust.*
FROM event_cust
WHERE TimeValue([start_time]) >= CDate([Forms]![CustEventRptForm]![FromHour])
AND TimeValue([start_time]) <= CDate([Forms]![CustEventRptForm]![ToHour])

hide rows with zero value -- crystal reports

I have the following table in Crystal Reports 2010:
Name------------Number----Line----Price-----InvoiceNum
CustomerX-------800---------2------$100----------1
CustomerX-------800---------4------$0-------------1
CustomerX-------800---------4------$0-------------1
CustomerX-------800---------4------$900----------1
CustomerX-------800---------3------$0-------------1
CustomerX-------800---------3------$0-------------1
CustomerX-------800---------3------$1900---------1
CustomerX-------800---------2------$0-------------1
CustomerX-------800---------2------$0-------------1
I want to suppress the rows that are duplicates and have $0 value, so I need somethings like this:
CustomerX-------800---------2------$100----------1
CustomerX-------800---------4------$900----------1
CustomerX-------800---------3------$1900---------1
At section expert if I use this formula for suppressing it will hide all rows that have Price as $0 value.
if {#Price}=0 then true else false
But I only want to hide the $0 value if there are duplicate Line numbers for same InvoiceNum.
I also tried this:
if ({#Price}=0 and {#Price}=previous({#Price})) then true else false
but it would not remove all of the zero-values, just a part.
Go Report >Selection Formula>Record then Select your Fields As is
{Supplier.ClosingBalance} <>0

Nested if else Condition in Crystal report

I have a .rpt file , with a view datasource . I have four parameter which i use in filtering the selection. I have written my selection formula like below.
if ({?actype} <> "All") OR ({?actype} <> "All") OR ({?collectorname} <> "All") OR ({?batchno}<> "All") Then
(
if {?actype} <> "All" Then
{CollectorPerformance.accountType} = {?actype};
if {?collectorname} <> "All" Then
{CollectorPerformance.realname} = {?collectorname};
if {?batchno} <> "All" Then
{CollectorPerformance.batchno} = {?batchno}
and
{CollectorPerformance.clientid} = {?clientid}
and
Date({CollectorPerformance.paymentdate}) >= Date({?from})
and
Date({CollectorPerformance.paymentdate}) <= Date({?to})
)
My issue with the formula, above is that it does not filter by realname and actType. I understand the reason is because the key word "and" is missing . however, it filters the batchno correctly> please how do i make it filter by the remaining two if's ? any help would appreciated.
A selection formula has to be one long valid boolean statement, which is, I think, what you were already suggesting when you say the "and is missing". So in order to fix the first half, you just need to translate those statements into one simplified boolean statement instead of individual statements (those that end in a ';').
({?actype}="All" or {?actype}={CollectorPerformance.accountType})
and
({?collectorname}="All" or {?collectorname}={CollectorPerformance.realname})
and
({?batchno}="All" or {?batchno}={CollectorPerformance.batchno})
...
For each parameter, a user can either select "All" or enter a specific value to filter by. If "All" is selected, that particular portion of the statement (The part that looks like {?Parameter}="All") will evaluate to True and no filtering will be done. Otherwise, only records matching the entered parameter value will return True.

How to filter rows with null values in any of its columns in SSRS

I want to filter out the output without rows containing null values or blank columns. I am using SQL Server 2012 there is no option named 'Blank' as in SS2005 where I can filter the rows. I also tried following expression but it gives me error or not showing correct output
=IsNothing(Fields!ABC.Value)!= True
=Fields!ABC.Value = ''
Please suggest the solution.
Pull up the tablix or group properties
Switch to "Filters"
Add a new filter
Set the expression to:
=IsNothing(Fields!YourFieldHere.Value)
Set the type to "Boolean" (see screenshot below) otherwise you'll get a "cannot compare data of types boolean and string" error.
Set the value to false
This works for filtering both rows and groups.
We should use the isNothing method in the Expression, change the Text to Boolean
and then Value will be "True"
for example:
Expression
=IsNothing(Fields!TestA.Value)<>True
(Expression type should be Boolean)
Operator
=
Value
=True
Edit the SQL query, so that it will not return NULL values in the column to group on, but let it return a dummy value; for example: ISNULL(columnA, 'dummy')
In the column group definition add a filter: ColumnA <> 'dummy'.

String comparisons in JasperReports expressions

A database field named income_source is queried using:
SELECT * FROM table_name WHERE income_source LIKE "salaried%"
This retrieves income_source values with a "salaried" prefix. In iReport, the PrintWhenExpression value for the field is set as:
$F{income_source}.equals("Salaried")? Boolean.TRUE:Boolean.FALSE
Why does the report output differ from the SQL output?
There are a few problems:
The value "salaried%" in the SQL differs from the value of "Salaried" in the expression.
The value "salaried%" uses the % to match all text after the letter d.
There is a bit of redundancy in the PrintWhenExpression.
Try the following expression:
$F{income_source}.startsWith( "salaried" )
Or:
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )
One of those should work. You will also want to ensure Blank when null is checked. Otherwise, the expression becomes:
$F{income_source} == null ? Boolean.FALSE :
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )