Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Handling database nulls Post Reply Post New Topic
Author Message
sirlansa
Newbie
Newbie
Avatar

Joined: 20 Dec 2006
Location: United States
Online Status: Offline
Posts: 37
Quote sirlansa Replybullet Topic: Handling database nulls
    Posted: 27 Nov 2007 at 11:57am
Our existing SQL Server 2005 db has table with a number of numeric flds containing NULLS. I am writing a bunch of custom functions in CR X that call each other and ultimately reference these NULL-ridden flds. The functions of course return NULL when they encounter a null input fld.
 
I have 3 approaches (listed in order of decreasing desirability) to solving this problem:
     * Use the File=>Options=> Reporting => 'Convert db NULL values to defaults'. This would be the best approach since it is universal and requires no code changes, BUT checking this option seems to have no effect at all!!
 
     * Use the builtin isnull() function to check each potentially NULL fld and substitute its default (0 for numerics).  I always get an error message saying that ISNULL() can't be used inside custom functions. Functions apparently can be built only with Basic Syntax, so I haven't tried this with Crystal Syntax.
 
     * Create a formula for every potentially null field and set it to the default if null. Then change all the function calls to use the formula instead of the database field directly. This works if the formula uses Basic syntax. It is a pain to do all this, and will increase the maintenance of these fields and possibly decrease performance.
 
Can anyone think of another approach or suggest why the first (and best) approach isn't working??
Sir Lansa
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 27 Nov 2007 at 1:12pm

The first option should work for any "formula". I am wondering when you are using a function if it runs before any conversion by a formula to make the Null a default value. When I look at the function editor it does not seem to allow for the setting of default values for nulls. That make me think you will need to deal with nulls in the code. ISNULL function does work in both Basic and CR syntax (at least in XI). Assuming it does in X then your second choice may be the best of the remaining options.

Perhaps others can suggest another alternative, such as dealing with it through SQL

Regards,

John W.
www.CustomReportWriters.net

IP IP Logged
sirlansa
Newbie
Newbie
Avatar

Joined: 20 Dec 2006
Location: United States
Online Status: Offline
Posts: 37
Quote sirlansa Replybullet Posted: 27 Nov 2007 at 2:09pm
Given that I may have to use option #2, can anyone give me a shortexample of a custom function written in Crystal syntax?
Sir Lansa
IP IP Logged
sirlansa
Newbie
Newbie
Avatar

Joined: 20 Dec 2006
Location: United States
Online Status: Offline
Posts: 37
Quote sirlansa Replybullet Posted: 28 Nov 2007 at 6:41am
Well, as often happens, I solved my own problem. The solution to getting the first option above to work is:
 
Use the File=>Report Options=>Reporting => 'Convert db NULL values to defaults', instead of the File=>Options=>Reporting => 'Convert db NULL values to defaults' that I had been trying.
 
The Report Options dialog apparently affects only the current report, so it has to be set in every report where I want this conversion to take place. I still don't know why the 'global' setting had no effect!
Sir Lansa
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 28 Nov 2007 at 8:58am
I had no idea that the global option wouldn't work in all circumstances. I wonder if maybe the report only option was set a while back and once done, then it overrides the global setting? That's would be an interesting thing to test.

Thanks for the update!
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.000 seconds.