Crystal Reports 2008 - Problem with NULL in SQL query

I am using Crystal Reports 2008 and trying to run a SQL expression query on an Oracle database. However, the query does not behave as I expected it to.
The database keeps returning NULL values for the field when I am trying to filter them out.

When I use:
(select "TAGENT"."CODE" from "TAGENT"

The query returns all the correct fields as well as the one containing blank values.
(12869 NULL values and all the other fields which total 408) = 13277 fields

If I change to look at only NULL values:
(select "TAGENT"."CODE" from "TAGENT"

The query then returns one filed containing 13277 fields showing as blank value.

"TAGENT".”CODE” is a String (10)
"TAGENT".”REFERENCE” is a Number

I have created a Sub Report in Crystal which when I use selection formulas and look at the SQL query it creates I get (The dates are for the lastfullmonth):
 WHERE  ("TJOBS"."PICKUP_DATE">=TO_DATE ('01-02-2014 00:00:00', 'DD-MM-YYYY HH24:MI:SS') AND "TJOBS"."PICKUP_DATE"<TO_DATE ('01-03-2014 00:00:00', 'DD-MM-YYYY HH24:MI:SS')) AND (select "TAGENT"."CODE" from "TAGENT"

This query works and I get just the 408 records I am expecting.

Can someone please shed some light on how I get a single SQL expression Field to work the as the expression works in the sub report when using selection formulas.

Who is Participating?
Kurt ReinhardtSr. Business Intelligence Consultant/ArchitectCommented:
The database keeps returning NULL values for the field when I am trying to filter them out.

The problem is you're NOT filtering them out of the report.  A SQL Expression will return a single distinct value when the conditions of the expression are met.  in this case, you want want records that aren't NULl and you're getting them when that condition is met.  Otherwise, you're getting NULLs because the expression is still running against every detail record in you report.

If you really want to filter out records where the value is NULL from appearing in your report at all, the next step is to use the SQL Expression in your record selection criteria as something like:

Not IsNull({%Code})

This would ensure your report efficiently filters out all records where there is no code.
WHere are you using the queries?

I notice the first 2 refer to a second table that isn't included in the query.

At the end you use the term SQL Expression.  Are you trying to build a Crystal SQL Expression or are you just using that in a generic sense?

BizataniumAuthor Commented:
I am using these queries in Crystal Reports 2008 as a Crystal SQL Expression.

The 1st 2 SQL queries shown are Crystal SQL expression formulas.

the last one is the the SQL query in the sub report that you get when you select Show SQL Query from the database menu in Crystal.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

I asked about the SQL Expression because a Crystal SQL expression can only return a SINGLE value so it can't be returning that many rows or fields.

Why do you think it is returning that many values?

BizataniumAuthor Commented:
I am trying to get just one value from the SQL expression

Based on the the parameters:

"TAGENT".”CODE” is then returned, but it also returns the values where "TAGENT".”CODE” has no value (which means "TAGENT".”REFERENCE” has no value)

I then try and use this in a Cross Tab, but I get all the correct rows as well as the NULL rows.

To get around this I can write a Crystal formula called Worth Reporting where it checks if the result of the Crystal SQL Expression is Null:
Not Isnull({%Subbed})

Then by adding another column & filtering out the False values my table will look correct.

I had hoped to be able to get the correct data from the original Crystal SQL expression without then having to filter out the data even more.

Kurt ReinhardtSr. Business Intelligence Consultant/ArchitectCommented:
On a side note, what version of Oracle are you using and what driver?  In the past, I haven't ever been able to get a full SELECT Oracle SQL Expression to correlate to a field in the report.
BizataniumAuthor Commented:
I had thought this might be the case, as you’re stated the expression is running against every detail in the report.

Using a SQL expression in my record selection criteria is what I’ve done in the sub report that works, I had just hoped it was possible to combine that into a single Crystal SQL expression.

The work around I have ended up choosing is to use the Not IsNull({%Code}) as the 1st Row in my Cross-Tab and then only showing TRUE values and having the detail in Row 2, which does the trick without filtering out data that will be needed in the rest of the report.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.