?
Solved

Crystal Reports 2008 - Problem with NULL in SQL query

Posted on 2014-03-27
7
Medium Priority
?
1,955 Views
Last Modified: 2014-03-27
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"
where "TAGENT"."REFERENCE" = "TJOBS"."AGENT_REF"
AND ("TAGENT"."REFERENCE")IS NOT NULL)

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"
where "TAGENT"."REFERENCE" = "TJOBS"."AGENT_REF"
AND ("TAGENT"."REFERENCE")IS NULL)

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):
 SELECT "TJOBS"."PICKUP_DATE", "TJOBS"."REFERENCE", (select "TAGENT"."CODE" from "TAGENT"
where "TAGENT"."REFERENCE" = "TJOBS"."AGENT_REF")
 FROM   "FREEDOM_LIVE"."TJOBS" "TJOBS"
 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"
where "TAGENT"."REFERENCE" = "TJOBS"."AGENT_REF") IS  NOT  NULL

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.

Thanks
0
Comment
Question by:Bizatanium
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 39958772
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?

mlmcc
0
 
LVL 1

Author Comment

by:Bizatanium
ID: 39958788
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.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 39958876
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?

mlmcc
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:Bizatanium
ID: 39959010
I am trying to get just one value from the SQL expression
"TAGENT".”CODE”

Based on the the parameters:
"TAGENT"."REFERENCE" = "TJOBS"."AGENT_REF"
"TAGENT".”REFERENCE" IS NOT NULL

"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.

Thanks
0
 
LVL 26

Accepted Solution

by:
Kurt Reinhardt earned 1500 total points
ID: 39959549
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.
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 39959554
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.
0
 
LVL 1

Author Closing Comment

by:Bizatanium
ID: 39959782
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to recover a database from a user managed backup
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question