Improve company productivity with a Business Account.Sign Up

x
?
Solved

Crystal Reports 2008 - Problem with NULL in SQL query

Posted on 2014-03-27
7
Medium Priority
?
2,021 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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.

Join & Write a Comment

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

585 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